Validation not working!!!!!

Results 1 to 2 of 2

Thread: Validation not working!!!!!

  1. #1
    Join Date
    Dec 1969

    Default Validation not working!!!!!

    When I try to run this function it doesn&#039;t understand<BR>window.document.forms[index].value<BR>Can anyone help?<BR>function validate()<BR>{<BR>var counter = document.the_form.counter.value;<BR>for(index=0;in dex&#060;counter;index++)<BR>{<BR>if (window.document.forms[index].value=NaN ) <BR> { <BR> alert("Please enter an integer value")<BR> return (false); <BR> }<BR> else<BR> {<BR> return true;<BR> }<BR>}<BR>}<BR>

  2. #2
    Join Date
    Dec 1969

    Default Becuz you coded it wrong...

    document.forms[n] refers to FORM NUMBER n, *NOT* to element number n within a given form!<BR><BR>You wanted:<BR><BR>document.the_form.elements[index].value<BR><BR>Except that your code wouldn&#039;t work, anyway. Because the ".value" property of a text field is *ALWAYS* a *string*. So it will *never* be NaN.<BR><BR>What you wanted is:<BR><BR>if ( isNaN( parseInt( document.the_form.elements[index].value ) ) )<BR><BR>or something along those lines.<BR><BR>Time to go hit the JS docs again. I&#039;d recommend the Netscape docs...they are much better organized and easier to read than the MSIE ones, and you wouldn&#039;t have made mistakes such as those if you&#039;d read them, I believe.<BR><BR>Such as these:<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts