That said, it is possible to give you the basic layout of a script, which you can then customise to the needs of your form.Ī general script looks like this: function checkform() It's impossible for me to give you a definitive validation script, as every form is different, with a different structure and different values to check for. Of course, if there are no problems, the function call will be replaced by true and the data will be submitted. Submit's default action is to submit the data, but if you give onSubmit a value of return false, it will not be submitted just like how we can stop a link from being followed. If you've learnt your functions properly, you should be able to guess that our function will return a Boolean value - either true or false. ![]() Where checkForm is the name of the function we're about to create. Add an attribute like this to the form you wish to validate: We're going to be checking the form using a function, which will be activated by the form's submit event - therefore, using the onSubmit handler. It's also very precise, as you can point out the exact field where there's a problem. ![]() ![]() It makes your page much more user-friendly, and takes out the frustration of having to fill out the same form repeatedly. The CGI script is still more reliable, as it always works regardless of whether JavaScript is enabled on the client-side or not but having this extra safety barrier is a nice thing to have in place. ![]() A JavaScript check is useful because it stops the form from being submitted if there is a problem, saving lots of time for your readers. If it finds any it sends the page back to the reader who then has to re-enter some data, before submitting again. When you submit a form to a CGI program that resides on the server, it is usually programmed to do its own check for errors.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |