Chapter 5: Forms
173
So, an onsubmit attribute on the <form> element might look like this:
onsubmit=”validateFormDetails();”
We will look at scripts in Chapters 11 and 12, but for the moment all you need to know is that, in the line
of code above, the...
More
Chapter 5: Forms
173
So, an onsubmit attribute on the <form> element might look like this:
onsubmit=”validateFormDetails();”
We will look at scripts in Chapters 11 and 12, but for the moment all you need to know is that, in the line
of code above, the onsubmit attribute tells the browser that when the user presses the submit button, the
browser should run the script called validateFormDetails(), and that this script is probably in the
<head> element.
There are two key advantages to making some checks on the form before it is sent to the server:
If users have missed information, they do not have to wait the extra time it would take for the
page to be sent to the server and then returned with details of their errors.
It is far quicker if it is
checked in the browser first.
The server does not have to receive as many forms with errors, because the browser will have
already made some checks before it receives the data (therefore, saving the load on the server).
The onreset Attribute
So
Less