JavaScript form onSubmit handling -
i new javascript , have been searching threads here can't figure out why forms not running through validation properly. have tried adding alerts find issue, , seems somewhere around first if statement. ideas? thanks!
<script type="text/javascript"> function datacheck() { var firstname = document.getelementbyid("firstname").value; var firstname = document.myform.firstname.value; var lastname = document.getelementbyid("lastname").value; var facilitator = document.getelementbyid("facilitator").value; //validate firstname field minimum of 2 characters if (firstname.length < 2){ alert("please come in first name minimum of 2 characters"); homecoming false; } else {retvalue = true} //validate lastname field min length , numeric or alpha characters if (lastname.length < 2 || lastname.){ alert("please come in lastly name minimum of 2 characters"); homecoming false; } if( /[^a-za-z0-9]/.test(lastname) ) { alert("last name must alphanumeric."); homecoming false; } } </script> <form action="http://bucs601.com/submit.php" name="myform" onsubmit="return datacheck()" method="post"> first name: <input type="text" id="firstname" name="firstname"><br> lastly name: <input type="text" id="lastname" name="lastname"><br> email: <input type="text" id="email" name="email"><br> facilitator: <input type="text" id="facilitator" name="facilitator"> <input type="submit" id="submit" value="submit"> </form>
the 1 obvious error can see incomplete line:
if (lastname.length < 2 || lastname.){
what sec status supposed be? if remove "|| lastname." bit function seems work ok.
javascript onsubmit
No comments:
Post a Comment