javascript - Getting "null or not an object" error when validating form -


i'm using this:

<script type="text/javascript">     var emailrule = /^[_\w\-]+(\.[\w\-]+)*(\.[\d]{2,3})$/;      if (emailrule.test(document.forms[0].email.value))         window.alert("that valid email address");     else         window.alert("that not valid email address"); </script> 

to validate this:

<form action="">     <p>email: <input type="text" name="email"/>     <input type="submit" value="sign up"/></p>     <br> </form> 

that form form on page , input box form element on page. error:

document.forms.0.email null or not object 

i've tried changing document.forms[0].elements[0].value same type of error.

because calling page renders element not exist yet.

you need have code wrapped in validation function called onsubmit.


Popular posts from this blog

Php - Delimiter must not be alphanumeric or backslash -

Delphi interface implements -

java - How to create Table using Apache PDFBox -