OnReset, OnResize and Other JavaScript Events - OnSubmit
(Page 4 of 5 )
The OnSubmit event is triggered when a user clicks the Submit button on a form. In the sample below, I refer to a page called someformpage.htm. This is the page that the form will redirect to when the Submit button is pressed. If you don’t create the page in your directory prior to running this script, it will not load the page. But never fret, the rest of the code will work.
<html>
<body>
Enter your name fool!
<form name="thisform" action="someformpage.htm"
onSubmit="alert('I think the name ' + thisform.thisfield.value + ' is stupid' + '!')">
<input type="text" name="thisfield" size="10">
<input type="submit" value="Do it!">
</form>
</body>
</html>
The above code creates a form. The text field named thisfield has a caption that demands: Enter your name fool! When the foolish user enters their name and clicks the Do It! Button (really it’s just a submit button), it triggers a pop-up alert that insults the user: I think the name (user’s name) is stupid! and redirects to the someformpage.htm page.

Supporting HTML tags: <form>
Supporting Javascript Objects: form
Next: OnUnLoad >>
More JavaScript Articles
More By James Payne