View Full Version : Strange problem validation of date

08-25-2004, 09:21 AM
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">
<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>
<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>
<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="" >
<td width="72">
<input type="button" name="Submit42" value="Add More" onClick="addLine()" ></td>
<td width="8">&nbsp;</td>

08-25-2004, 10:34 AM
eeer you forgot to show us the javascript code...

Anyway... try puting the object.focus() code line after the alert() message.

Willy Duitt
08-25-2004, 10:46 AM
Try using onchange as opposed to onblur....


08-25-2004, 11:26 AM
I suggest you to not to use onblur to validate fields as users may experience endless alert loop in some browsers or not focusing at all as you're experiencing right now. Validate on form onsubmit event instead, it's user-friendlier.

08-25-2004, 01:52 PM
What about onkeyup?

08-25-2004, 02:28 PM
onkeyup is going to call the validation code on every stroke, not good.

Validation should be done on the submit, I have found that users see that as less fustrating and they are not being force fed.


08-25-2004, 07:11 PM
It is recommended t use validation only on submit

08-25-2004, 07:11 PM
I have concluded to use validation only on submit

08-26-2004, 10:14 AM
It is recommended t use validation only on submit

With some exceptions, maybe...
For instance... a limitator of maximum allowed number of characters folowed by a 'counter' (for user to see when he is about to reach the limit). It is obvious to me that kind of validator should be done sequential, thus it should be handled by a "local" event, such as onkeyup or onchange.