By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,945 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,945 IT Pros & Developers. It's quick & easy.

Why is it that the onsubmit event doesn't work ?

P: 1
I noticed that the onclick event works but the onsubmit doesn't why is it ?

Below is the code of my form. Please help me resolve this issue.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Form</title>
  4. <SCRIPT LANGUAGE="Javascript">
  5. <!-- Displays the name in the second textbox
  6. function displayName()
  7. {
  8.     var d1=document.personalForm.firstName.value;
  9.     document.personalForm.fname.value=d1;    
  10.  
  11. }
  12. Ends Here-->
  13. </SCRIPT>
  14. </head>
  15. <body onLoad="displaymessage()">
  16. <table border="0">
  17. <Form name="personalForm" method="post">
  18. <tr>
  19. <td width="100px"><label>Name :</label></td><td><input type="text" name="firstName"></td>
  20. </tr>
  21. <tr>
  22. <td width="100px" height="26"><label>Password :</label></td><td><input type="Password" name="pwd"></td>
  23. </tr>
  24. <td width="300px"><label>Date of Birth :</label></td><td><select name="day">            
  25. <SCRIPT LANGUAGE="Javascript">
  26. <!--Hide
  27. var d;
  28.  
  29. for(d=1;d<=31;d++)
  30. {
  31.     document.write("<option value=\"d\">",d,"</option>");
  32.  
  33. }
  34. -->
  35. </SCRIPT>                                       
  36. </select> 
  37. <select name="month"><option value="January">Jan</option><option value="February">Feb</option><option value="March">Mar</option><option value="April">Apr</option><option value="May">May</option><option value="June">Jun</option>
  38. <option value="July">Jul</option><option value="August">Aug</option><option value="September">Sep</option><option value="October">Oct</option><option value="November">Nov</option><option value="December">Dec</option></select>
  39. <select name="year">
  40. <SCRIPT LANGUAGE="Javascript">
  41. <!--Hide
  42. var y;
  43.  
  44. for(y=1900;y<=1996;y++)
  45. {
  46.     document.write("<option value=\"y\">",y,"</option>");
  47.  
  48. }
  49. -->
  50. </SCRIPT>                                       
  51. </select> 
  52. </td>
  53. <td height="37"></tr>
  54. <tr>
  55. <td><label>Sex :</label></td><td><input type="radio" name="sex" value="male" checked="checked"><label>Male</label>
  56. <input type="radio" name="sex" value="female"><label>Female</label>
  57. </td>
  58. </tr>
  59. <tr><td><label>Your name is:</label></td><td><input type="text" name="fname"></td></tr>
  60. </form>
  61. <tr><td colspan="2"><center>
  62.   <input type="Submit" value="Submit" onsubmit="displayName()"/>
  63. </center></td>
  64. </table>
  65. </body>
  66. </html><html>
  67. <head>
  68. <title>Form</title>
  69. <SCRIPT LANGUAGE="Javascript">
  70. <!-- Displays the name in the second textbox
  71. function displayName()
  72. {
  73.     var d1=document.personalForm.firstName.value;
  74.     document.personalForm.fname.value=d1;    
  75.  
  76. }
  77. Ends Here-->
  78. </SCRIPT>
  79. </head>
  80. <body onLoad="displaymessage()">
  81. <table border="0">
  82. <Form name="personalForm" method="post">
  83. <tr>
  84. <td width="100px"><label>Name :</label></td><td><input type="text" name="firstName"></td>
  85. </tr>
  86. <tr>
  87. <td width="100px" height="26"><label>Password :</label></td><td><input type="Password" name="pwd"></td>
  88. </tr>
  89. <td width="300px"><label>Date of Birth :</label></td><td><select name="day">            
  90. <SCRIPT LANGUAGE="Javascript">
  91. <!--Hide
  92. var d;
  93.  
  94. for(d=1;d<=31;d++)
  95. {
  96.     document.write("<option value=\"d\">",d,"</option>");
  97.  
  98. }
  99. -->
  100. </SCRIPT>                                       
  101. </select> 
  102. <select name="month"><option value="January">Jan</option><option value="February">Feb</option><option value="March">Mar</option><option value="April">Apr</option><option value="May">May</option><option value="June">Jun</option>
  103. <option value="July">Jul</option><option value="August">Aug</option><option value="September">Sep</option><option value="October">Oct</option><option value="November">Nov</option><option value="December">Dec</option></select>
  104. <select name="year">
  105. <SCRIPT LANGUAGE="Javascript">
  106. <!--Hide
  107. var y;
  108.  
  109. for(y=1900;y<=1996;y++)
  110. {
  111.     document.write("<option value=\"y\">",y,"</option>");
  112.  
  113. }
  114. -->
  115. </SCRIPT>                                       
  116. </select> 
  117. </td>
  118. <td height="37"></tr>
  119. <tr>
  120. <td><label>Sex :</label></td><td><input type="radio" name="sex" value="male" checked="checked"><label>Male</label>
  121. <input type="radio" name="sex" value="female"><label>Female</label>
  122. </td>
  123. </tr>
  124. <tr><td><label>Your name is:</label></td><td><input type="text" name="fname"></td></tr>
  125. </form>
  126. <tr><td colspan="2"><center>
  127.   <input type="Submit" value="Submit" onsubmit="displayName()"/>
  128. </center></td>
  129. </table>
  130. </body>
  131. </html>
Jul 29 '09 #1
Share this Question
Share on Google+
2 Replies


gits
Expert Mod 5K+
P: 5,390
i guess that it behaves like that because the submit-buttons are outside of the form-tags ...
Jul 31 '09 #2

Canabeez
100+
P: 126
And I think the onSubmit="" should be under <FORM>, not under <INPUT>.
Aug 2 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.