Monday, 15 August 2011

javascript - JSP Java Script validation not working -



javascript - JSP Java Script validation not working -

i wrote java script code in jsp page,but when seek submit page, javascript validation code not getting fired,could 1 help me went wrong?

here code:

<html> <center><h3>employee absent report</h3></center> <head> <script language="javascript" type="text/javascript"> function onformsubmit(){ var counterrors = 0; var strdt=document.getelementbyid("startdate").value; var enddt=document.getelementbyid("todate").value; var flag=false; var eflag = false; if (isempty(strdt)==false && isempty(enddt)==true ) { document.getelementbyid("divexpirydate").innerhtml = "* please come in expiry date"; homecoming false; } if (isempty(strdt)==true && isempty(enddt)==false ) { document.getelementbyid("divstartdate").innerhtml = "* please come in start date"; homecoming false; } homecoming true; } </script> </head> <body> <form name="form" action="formservlet" method="get" onsubmit="return onformsubmit(); "> <center> <div id="formerrors" class="error"></div> fromdate: <input type="text" name="startdate" id="startdate"/> <div id="divstartdate"></div> <br> todate: <input type="text" name="todate" id="todate"/> <div id="divexpirydate"> </div> <br> <input type="submit" value="submit"/> </center> </form> </body> </html>

looks logical error me. seek replacing this:

if (isempty(strdt)==false && isempty(enddt)==true ) { document.getelementbyid("divexpirydate").innerhtml = "* please come in expiry date"; homecoming false; } if (isempty(strdt)==true && isempty(enddt)==false ) { document.getelementbyid("divstartdate").innerhtml = "* please come in start date"; homecoming false; }

with:

if (enddt.length==0) { document.getelementbyid("divexpirydate").innerhtml = "* please come in expiry date"; homecoming false; } if (strdt.length==0) { document.getelementbyid("divstartdate").innerhtml = "* please come in start date"; homecoming false; }

javascript jsp

No comments:

Post a Comment