|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
date validation somethimes work
I ahve 2 subsequent date fields
say dt1 and dt2 I have date validation routine and calling it on "onblur" event so as to validate the date field before ficusing on next field How I am calling it " blur(this) " The default value stored in date field is today's date is "dd-mm-yyyy" The program is goding in lioop when wrong date is entered it say apprpropriate mesage However the control (focus) is on next field(even though the date is incorrect' why should it happen ?? please help I am callind same fuction in same program to validate dat (which is first field) and set focus is occuring properly The html code in which I am using date validation para <tr bgcolor="#FFFFFF"> <td height="49" class="text-b12"> <div align="center"> <input name="containerno0" type="text" class="text-b12" id="containerno0" size="12" maxlength="12" onBlur="chkcontainerno(this)" > <input name="containers" type="hidden" id="containers"> </div></td> <td> <div align="center"> <select name="containersize0" class="text-b12"> <option value="1" class="text-b12">6 '</option> <option value="2" class="text-b12">10'</option> <option value="3" class="text-b12">20'</option> <option value="4" class="text-b12">40'</option> <option value="5" class="text-b12">40 HC</option> <option value="6" class="text-b12">20 HC</option> </select> </div></td> <td> <div align="center" class="text-b12"> <select name="containertype0" class="text-b12"> <option value="1">OT</option> <option value="2">TR</option> <option value="3">GP</option> <option value="4">RF</option> </select> </div></td> <td> <input name="pikupdate0" type="text" class="text-b12" id="pikupdate0" value="<? echo "dd-mm-yyyy" ?>" size="12" maxlength="12" onblur="return chkdate(this)" > <input name="pikupdate0_ymd" type="hidden" id="pikupdate0_ymd"> . </td> <td width="72"> <input name="stuffdate0" type="text" class="text-b12" id="stuffdate0" value="<? echo $dmy ?>" size="12" maxlength="12" onblur="return chkdate(this)" ></td> <td> <input name="packages0" type="text" id="packages0" size="5" maxlength="5" class="text-b12" onBlur="chkpkgs(this)" ></td> <td><input name="movedondate0" type="text" class="text-b12" id="movedondate0" value="<? echo $dmy ?>" size="12" maxlength="12" onblur="return chkdate(this)"></td> <td><input name="loadondate0" type="text" class="text-b12" id="loadondate0" value="<? echo $dmy ?>" size="12" maxlength="12" onblur="return chkdate(this)"></td> <td><div align="center"> <input name="vessalno0" type="text" class="text-b12" id="vessalno0" size="8" maxlength="8" onBlur="" > </div></td> <td width="72"> <input type="button" name="Submit42" value="Add More" onClick="addLine()" ></td> <td width="8"> </td> </tr> Code (javascrpt) for date validation function chkdate(inpdate) { idate=inpdate.value; if (idate.length > 10) { alert("date cannot exceed more than 10 characters and should be in format dd-mm-yyyy") ; inpdate.focus(); return false; } var dsh1 = idate.substring(3,2); //alert (dsh1); var dsh2 = idate.substring(6,5); //alert (dsh2); if (dsh1 != "-" ) { alert ("Enter date in dd-mm-yyyy format >>> there is no '-' after day "); inpdate.focus(); return false } if (dsh2 != "-" ) { alert ("Enter date in dd-mm-yyyy format >>> there is no '-' after month "); inpdate.focus(); return false; } var yr=idate.substring(6,10); var mm=idate.substring(3,5); var dd=idate.substring(0,2); //alert(yr+' Year'); //alert(mm+' Month'); //alert(dd+' Day'); if (isNaN(dd)) { alert ("Day of month should be numeric "); inpdate.focus(); return false; } if (isNaN(mm)) { alert ("Month should be numeric "); inpdate.focus(); return false; } if (isNaN(yr)) { alert ("Year should be numeric "); inpdate.focus(); return false; } if (yr < 2003) { alert ("Year should be greater than 2002 "); inpdate.focus(); return false; } if (yr.length != 4 ) { alert ("Year should be 4 digits in year"); inpdate.focus(); return false; } if (dd < 1) { alert ("Day of month cannot be less than 1 "); inpdate.focus(); return false; } if (dd > 31 ) { alert ("Day cannot be Greater than 31 "); inpdate.focus(); return false; } if (mm > 12 || mm < 1 ) { alert ("Month should be between 1 and 12 "); inpdate.focus(); return false; } if (mm == 6 || mm == 9 || mm==11 ) { if (dd > 30 ) { alert ("There are 30 days in June, September and November !! please correct day "); inpdate.focus(); return false; } } if (mm==2) { var b=parseInt(yr /4); if (isNaN(b)) { alert( "Check no.of days in February NOT valid"); inpdate.focus(); return false ; } if (dd>29) { alert("Check no.of days in February NOT valid days in February cannot exceed 29"); inpdate.focus(); return false ; } if (dd==29 && ((yr/4)!=parseInt(yr/4))) { alert( "Check no.of days !! This is NOt leap year "); inpdate.focus(); return false ; } } return true ; } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > date validation somethimes work |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|