Onsubmit event & onreset event | how to create submit button and reset button in java script

Two more useful event for processing form are onsubmit and onreset.These event fires when the user submit or reset the form.

1. <html>
2. <head><title>STUDENTWEBSITE</title>
3. <script type="text/javascript">
4. <!--
5. var helpArray=["Your Name here","Enter you Maild id here","Enter your Address here","Enter the Text studentwebsite.blogspot.com"];

6. function helpText(messageNum)
7. {
8. myForm.helpBox.value=helpArray[messageNum];
9. }

10. function formsubmit()
11. {
12. window.event.returnvalue=false;
13. if(confirm("Are you sure you want to submit?"))
14. window.event.returnvalue=ture;
15. }

16. function formresubmit()
17. {
18. window.event.returnvalue=false;
19. if(confirm("Are you sure you want to submit?"))
20. window.event.returnvalue=true;
21. }

22. //-->
23. </script>
24. <body>
25. <form id="myForm" onsubmit="formsubmit()" action="">

26. Name:<input type="text" name="name" value="Name" onfocus="helpText(0)" onblur="helpText(3)" ><br>
27. Email<input type="text" name="email" value="Emaill" onfocus="helpText(1)" onblur="helpText(3)" ><br>
28. Address<input type="text" name="name" value="ADDress" onfocus="helpText(2)" onblur="helpText(3)"><br>
29. <input type="button" value="Submit" onclick="formsubmit()">
30. <input type="button" value="Reset" onclick="formresubmit()">

31. help box<textarea name="helpBox" readonly="true">
32. </body>
33. </html>



Related post