Resetting a Form

After you successfully submit a form, it is a good idea to reset it so you can use the form again. For example, your app might include a form for adding new movies. Each time you add a new movie, you want the form to reset to its default state.

If you are using the validation attributes then you cannot reset a form simply by assigning empty strings to the form fields. If you assign an empty string to a required field then the field will be in an invalid state.

Instead, you should reset a form by calling the JavaScript reset() method. The reset() method throws a form back into its default state.

For example, here’s a simple form for entering a movie title:

<form id="frmAdd">    <div>        <label ...

Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.