JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old August 25th, 2004, 02:25 AM
vikaspa vikaspa is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 4 vikaspa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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">&nbsp;</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 ;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > date validation somethimes work


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway