wiqi Posted November 21, 2009 Share Posted November 21, 2009 Please help me to figure out why this form isnt working at all.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Registration Form</title> </head> <body> <script type='text/javascript'> function formValidator(){ var name = document.getElementById('name'); var email = document.getElementById('email'); var password = document.getElementById('password'); if(notEmpty(name, "Please enter only letters for your First name")){ if(lr(password, 6, 12)){ if(notEmpty(email, "Please enter only letters for your Last Name")){ return true; } } } return false; } function notEmpty(elem, helperMsg){ if(elem.value.length == 0){ alert(helperMsg); elem.focus(); return false; } return true; } function lr(elem, min, max){ var uInput = elem.value; if(uInput.length >= min && uInput.length <= max){ return true; }else{ alert("Please enter between " +min+ " and " +max+ " characters"); elem.focus(); return false; } } </SCRIPT> <form action='' onsubmit='return formValidator()' name='myform' method='get' > <table width="425" height="166" border="0"> <tr> <td colspan="2"><h1>Registration Form </h1></td> </tr> <tr> <td width="122">Name</td> <td width="287"> <input name="name" type="text" id="name" maxlength="15" /> </td> </tr> <tr> <td>Email Address </td> <td><input name="email" type="text" id="email" maxlength="15" /></td> </tr> <tr> <td>Password</td> <td><input name="password" type="password" id="password" /></td> </tr> <tr> <td> </td> <td><input type="button" name="Submit" value="Submit" onmouseover=" document.myform.submit()" /> <input type="reset" name="reset" value="Reset" /></td> </tr> </table> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted November 21, 2009 Share Posted November 21, 2009 A description about what it exactly is that isn't working and when along with what errors you might receive would be helpful. Just dumping your complete html page and expecting someone to figure out what your problem is not likely going to get you help any time soon. Quote Link to comment Share on other sites More sharing options...
wiqi Posted November 21, 2009 Author Share Posted November 21, 2009 Well, its form validation isnt working. it should shown a msgbox if name or email fields are empty or if password is shorter than 6 chars when mouse hovers over the submit button. i dunno why it isnt working Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 21, 2009 Share Posted November 21, 2009 this <input type="button" name="Submit" value="Submit" onmouseover=" document.myform.submit()" /> should be <input type="submit" name="Submit1" value="Submit" /> Quote Link to comment Share on other sites More sharing options...
wiqi Posted November 21, 2009 Author Share Posted November 21, 2009 @rajiv I have to include this mouse over function. its essential to fulfill the requirements of this page. Quote Link to comment Share on other sites More sharing options...
wiqi Posted November 22, 2009 Author Share Posted November 22, 2009 anyone? Please :'( Quote Link to comment Share on other sites More sharing options...
wiqi Posted November 22, 2009 Author Share Posted November 22, 2009 form validation should have to be done when mouse pointer is placed over the (onmouseover function) submit button. it seems like stop working when i include the onmouseover="document.myform.submit" as the default trigger for submit button. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 22, 2009 Share Posted November 22, 2009 have you tried <input type="submit" name="Submit1" value="Submit" onmouseover="this.form.submit()"/> Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted November 22, 2009 Share Posted November 22, 2009 Even though this is clearly homework, which is against the rules to post, I'll give you a nudge in the right direction. Your logic isn't very efficient. It makes far more sense to tie the validation function to the input's onmouseover event, and leave the actual form submission to clicking the button instead of blindly sticking event handlers in your code. In fact, if you re-read the question in your assignment, that's exactly what it's telling you to do. 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.