Previous Example-|-Next Example-|-Return to Chapter Listing

Example 12.17:
onreset: With a Fake Reset Button

[This example works with Netscape Navigator 3. It will not work with Internet Explorer 3.]

We've created a fake Reset button, and used onclick to run the confirmReset() function. The user sees a confirm box, and if he clicks on OK we use the form's reset method to reset the form. The reset method is the equivalent of clicking the Reset button, so it still runs the onreset event handler. Try changing the text and clicking on Reset. Try both OK and Cancel in the Confirm box.


In the HEAD we have this script: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- function confirmReset() { if (confirm("Are you sure you want to clear this form?")) { document.forms[0].reset() } } //--> </SCRIPT> In the BODY of the page we have this form: <form onreset="alert('The form has been cleared and returned to its original state.')"> <input type="text" value="Here's the text" size="20"> <input type="button" value="Reset" onclick="confirmReset()"> </form>
Previous Example-|-Next Example-|-Return to Chapter Listing