Two Laptop Bag*
The moose likes HTML, CSS and JavaScript and the fly likes problems during validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "problems during validation" Watch "problems during validation" New topic
Author

problems during validation

sushant prabhu
Ranch Hand

Joined: Mar 22, 2001
Posts: 66
in a field i have 2 validations to check
say 1 is a date check & another is a null value check & the user proceeds to the next field without entering in the first field then i keep getting alert boxes saying date error & null value error & i just cant do anything not even close the browser window. the only option left is to press ctrl + alt + del .
How do i overcome this drawback.
i am pasting my code here :
<html>
<head>
<script language="javascript">
function checknull(zulu)
{
if (zulu.value== "") //** Replace 'txt1' by the name of your TextBox
{
alert("This Field Cannot Be Null !!! ");
zulu.focus();
zulu.value= "";
}
}
// ********************************************************************************
function checknumber(zulu)
{
if (zulu.value != "") //** Replace 'txt2' by the name of your TextBox
{
if (isNaN(zulu.value)== true)
{
alert("Invalid Number !!!");
zulu.focus();
zulu.value="";
}
}
}
// ********************************************************************************
function checkdate(zulu)
{
var str;
var day, month, year, s1, s2;
var mod;
str= zulu.value;
day= str.substr(0,2);
month= str.substr(3,3);
year= str.substr(7,4);
s1= str.substr(2,1);
s2= str.substr(6,1);
mod= (year % 4);
//alert(s2);
if (zulu.value== "") //** Replace 'txt3' by the name of your TextBox
{
alert("Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if (isNaN(day)== true)
{
alert("Invalid Day1 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( (day.length) != 2 )
{
alert("Invalid Day2 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( ((day.length) == 2) && (day < 0 || day > 31) )
{
alert("Invalid Day3 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if (s1 != "-")
{
alert("Invalid Seperator1 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if (isNaN(month) == false)
{
alert("Invalid Month1 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( (isNaN(month) == true) && (month.length != 3) )
{
alert("Invalid Month2 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( (isNaN(month) == true) && (month.length == 3) && ((month != 'jan') && (month != 'feb') && (month != 'mar') && (month != 'apr') && (month != 'may') && (month != 'jun') && (month != 'jul') && (month != 'aug') && (month != 'sep') && (month != 'oct') && (month != 'nov') && (month != 'dec') && (month != 'JAN') && (month != 'FEB') && (month != 'MAR') && (month != 'APR') && (month != 'MAY') && (month != 'JUN') && (month != 'JUL') && (month != 'AUG') && (month != 'SEP') && (month != 'OCT') && (month != 'NOV') && (month != 'DEC') && (month !='Jan') && (month != 'Feb') && (month != 'Mar') && (month != 'Apr') && (month != 'May') && (month != 'Jun') && (month != 'Jul') && (month != 'Aug') && (month != 'Sep') && (month != 'Oct') && (month != 'Nov') && (month != 'Dec')) )
{
//alert(month.length);
alert("Invalid Month3 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( (day > 30) && ( (month= "apr") || (month= "APR") || (month= "Apr") || (month= "jun") || (month= "JUN") || (month= "Jun") || (month= "sep") || (month= "SEP") || (month= "Sep") ||(month= "nov") || (month= "NOV") || (month= "Nov")) )
{
alert("Invalid Date /n Day Cannot be Greater than 30 for the Month of " + month + " !!! /n Enter Date as DD-MMM-YYYY ");
}
else if (s2 != "-")
{
alert("Invalid Seperator2 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( isNaN(year) == true )
{
alert("Invalid Year !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( isNaN(year)== false && (year.length != 4 ) )
{
alert("Invalid Year !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( (isNaN(year)== false) && (year.length = 4 ) && ((year % 4)== 0) && ((month= "feb") || (month= "FEB")) && (day > 28) )
{
alert("Invalid Date /n Day Cannot be Greater than 28 for the Month of " + month + " in Leap Year !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( (isNaN(year)== false) && (year.length = 4 ) && ((year % 4) != 0) && ((month= "feb") || (month= "FEB")) && (day > 29) )
{
alert("Invalid Date /n Day Cannot be Greater than 29 for the Month of " + month + " !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
}
// ********************************************************************************
</script>
</head>
<body>
<form name="f1">
<table align="center" border="1" width="100%" cellspacing="1" cellpadding="1" bordercolor="black">
<tr>
<td>Null Validation:</td>
<td><input type="text" name="txt1" onblur="javascript:checknull(this);checknumber(this);" title="Null Not Allowed Here"></td>
</tr>
<tr>
<td>Number Validation:</td>
<td><input type="text" name="txt2" onblur="javascript:checknumber(this);" title="Only Numbers Allowed Here"></td>
</tr>
<tr>
<td>Date Validation:</td>
<td><input type="text" name="txt3" maxlength="11" onblur="javascript:checknull(this);checkdate(this);" title="Enter Date as: DD-MMM-YYYY"></td>
</tr>
</table>
</form>
</body>
</html>


Sushant Prabhu<br />SCJP2<br />SCWCD<br />OCA9i
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi Sushant,
which browser are you using? Netscape 4.*? are you using frames?
i remember i had the same problem because of the difference in even handling of the browsers for onBlur() event...
if u r on Netscape browser then try IE and see if you can reproduce the error. if you use Netscape6 or higher then i will have to think.
but i really believe its the different implementation of onBlur event handlers in browsers.
regards
maulin
sushant prabhu
Ranch Hand

Joined: Mar 22, 2001
Posts: 66
Hi Maulin
Thanks for the reply.
regarding browser i m using ie6.0
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi Sushant,
if you can send the code to me at my email in my profile i will have a look and fix the problem. it is hard for me to follow this way as i can't run the script and put my debugging stmts you know....
regards
maulin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problems during validation