sorry folks if this post is not pertaining to jsp. I could'nt find a forum for javascript in here. so I am posting it here.
I've a jsp with a <html:text> element which is supposed to accept year values only.
I've added an onblur js function to check if it is the correct entry.
My Js function is as follows:
now my jsp looks as follows:] <script type="text/javascript" > function isYear(yrval) { if (yrval==null || yrval=="" || yrval=="0") { alert("Invalid value in Year!!"); return false; } var nyr=Number(yrval); alert(yrval); alert(nyr); var curdt = new Date(); var cy = curdt.getFullYear(); alert(cy); if (nyr>cy) { alert("Calendar Year cannot be greater than "+cy); return false; } if (nyr)<(cy-1)) { alert("You cannot enter data prior to year "+cy-1); return false; } return true; }
Now the problem : The alerts in js function is showing as NaN. Even forHTML Code:<body> <div id="content"> <center> <html:form action="/Savedata"> <table id="mytbl" > <tr><td class="tbhr" colspan="2">YEAR</td></tr> <tr><td>Select Year:</td><td><html:text name="myvo" property="calYear" size="5" maxlength="4" onkeypress="return onlyNumbers();" onblur="return isYear(this.value);"/></td></tr> </html:form> </center> </div> </body>
valid inputs, it's displaying the same message.
Am i missing something here?