• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

problems during validation

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maulin
Thanks for the reply.
regarding browser i m using ie6.0
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic