Thursday, November 26, 2009

Javascript Date Validation / Comparison

Problem:
User enters two dates, say start date and end date, then we need to alert him if the start date is greater than end date.

Solution:
Assume we are getting the date to the input field using a datepicker.

First we have to convert the string into Date() object using
var dObj = new Date(year, month, date); (also note: the month value range from 0 to 11)
and we can compare the dates.

Example:
var x = document.formName;

//assume the date format is YYYY/MM/DD
var sDate1 = x.start_date.value;
var sDate = new Date(sDate1.split('/')[0], parseInt((sDate1.split('/')[1])-1), sDate1.split('/')[2]);
var eDate1 = x.end_date.value;
var eDate = new Date(eDate1.split('/')[0], parseInt((eDate1.split('/')[1])-1), eDate1.split('/')[2]);
if(eDate >= sDate)
{
    alert("End date is greater than start date; please try again....");
    return false;
}

-

Thursday, November 19, 2009

How to add month, days, years in a date

<?php
$day1 = "2008/10/20";

//add month
$day2 = date("Y/m/d", strtotime("+2 months", strtotime($day1)));
//"2008/12/20"
$day2 = date("Y/m/d", strtotime("+3 months", strtotime($day1)));
//"2009/01/20"
//add days
$day2 = date("Y/m/d", strtotime("+5 days", strtotime($day1))); //"2008/10/25"
$day2 = date("Y/m/d", strtotime("+20 days", strtotime($day1))); //"2008/11/09"
//years
$day2 = date("Y/m/d", strtotime("+2 years", strtotime($day1))); //"2010/10/20"
?>
Also we can add weeks.

Monday, July 20, 2009

Jquery PHP Ajax Pagination

Jquery PHP Mysql - Ajax paging with magic link trick.

Click Here

Thursday, June 18, 2009

ajax link on no javascript problem - jquery

Problem:
I use jquery for developing ajax processes.

like $("#myLink").click / load...

if the browser javascript disabled, then the ajax link will not work and the user cant go through the pages in the website...

Solution: http://yensdesign.com/2009/06/safe-ajax-links-using-jquery/

Saturday, May 16, 2009

Wednesday, May 6, 2009

Hidden page problem in ajax - Jquery

Problem in accessing hidden / remote file directly when using ajax...

http://beski.wordpress.com/2009/05/06/hidden-file-problem-in-ajax/

Tuesday, February 10, 2009

Remove / Hide Scroll Bars

To hide inactive scroll bars set...
overflow: auto;
(When need - will appear)

To hide permanent...
overflow: hidden;

To show...
overflow: scroll;

By this way to hide scroll bar for window use this css...
html, body { overflow: hidden; }


Refer this...
http://www.brunildo.org/test/Overflowxy2.html

Enjoy!

Saturday, January 17, 2009

Getting Radio Button vlaue in PHP

<?php
if(isset($_REQUEST['lang']))
{
$lang=$_REQUEST['lang'];
print($lang);
}
?>
<html>
<head>
<title>TEST</title>
</head>
<body>
<form method="post" action="#">
Please choose language:<br />
<input type="radio" name="lang" value="JAVA">JAVA<br />
<input type="radio" name="lang" value="VB">VB<br />
<input type="radio" name="lang" value="PHP">PHP<br />
<input type="submit" value="submit" name="submit">
</form>
</body>
</html>

Saturday, January 3, 2009

Disable Right Click using Javascript

Simple way yo disable right click:
<body oncontextmenu="return false;">


Using script:
<script>
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
return false;
}
function mousehandler(e){
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
</script>

From: http://www.reconn.us/content/view/36/45/


Now...
Can i disable right click only on images?
Yes, by using getElementsByTagName i can set no right click on images only

<script>
function noRtClk(){
return false;
}
//document.oncontextmenu = noRtClk;

var e=document.getElementsByTagName("img");
for(var i=0;i<e.length;i++)
{
e[i].oncontextmenu = noRtClk;
}
</script>

Reference: http://www.aglasshalffull.org/css-resources/Using-getElementsByTagName-and-getElementsByName.htm

Thats it.