Enter your name in the following box, then press the Submit button.
<form method="post" action="testpage.html" onsubmit="validate(); return false;">
<input type="text" id="yourname" />
<input type="button" value="Submit" onclick="validate();" />
NOTE: Because most browsers will submit the form when the "Enter" key is pressed, the onsubmit event handler has been added to the <form> tag to ensure that the form will validate if the user does not activate the "Submit" button, but presses the "Enter" key while focus is in the text box. Also notice the required form label for the text box.
This example also validates the form information, but feedback is displayed in another place within the page.
How many items are in a dozen? Enter the amount into the box below, then press the 'Check' button.
<form method="post" action="testpage.html" onsubmit="checkAnswer2(); return false;">
<p class="invis" id="answercorrect">Correct, there are 12 items in a dozen.</p>
<p class="invis" id="answerwrong">Incorrect. There are 12 items in a dozen.</p>
<label for="answerbox">Enter Answer:</label>
<input type="text" id="answerbox" />
<input type="submit" onclick="checkAnswer2()" value="Check" />
- Validate the form information with a server side script, then display the feedback on another page.