bhavin_85 Posted April 7, 2007 Share Posted April 7, 2007 hey guys ive written the following code to check through the lengths that are input into a form, however it doesnt seem to work ??? i cant figure out where im going wrong <? include('config.php'); ?> <html> <head> <script type="JavaScript"> function checkInput(){ if((document.registration.username.value.length < 5)||(document.registration.username.value.length < 12)){ alert ("Please enter a Username between 5 and 12 characters"); return false; } if((document.registration.password.value.length < 5)||(document.registration.password.value.length < 9)){ alert ("Please enter a Password between 5 and 9 characters"); return false; } } </script> <title>Registration</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <table align="center" valign="top" width="700" cols="3"> <tr> <td align="center" colspan="3"> <font size="+5">Online DVD Shop</font> </td></tr> <tr><td> To register for our online shop please complete the following form </td></tr> <tr><td> <form name="registration" method="post" action="" onSubmit="return checkInput();"> Username: <input name="username" type="text"></input></br></br> Password: <input name="password" type="text"></input></br></br> Name: <input name="name" type="text"></input></br></br> Telephone: <input name="telephone" type="text"></input></br></br> Email: <input name="email" type="text"></input></br></br> Address: <input name="address" type="text"></input></br></br> Zipcode: <input name="zipcode" type="text"></input></br></br> <input type="submit" value="Submit"></input> </form> </td></tr> </table> </body> </html> can any1 tell me what im doing wrong? your help is much appreciated Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted April 8, 2007 Share Posted April 8, 2007 Hi, why not use the maxlenght attribute instead saves you all the javascript programming. example: <input maxlength="100" name="address" type="text"> Quote Link to comment Share on other sites More sharing options...
veridicus Posted April 8, 2007 Share Posted April 8, 2007 What exactly isn't working? Is the form not posting or is the JS not performing the check properly? Quote Link to comment Share on other sites More sharing options...
nogray Posted April 9, 2007 Share Posted April 9, 2007 you're checking if the length is smaller than 5 and smaller than 12 if((document.registration.username.value.length < 5)||(document.registration.username.value.length < 12)){ Notice the < sign before the 5 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.