| Programming C# C++ (7) Delphi (618) Java (8) JavaScript (30) Document (8) Events (8) ExtJS (8) Strings (3) perl (9) php (4) VBScript (1) Visual Basic (1) |
Validating user input in a form
Question: How can I validate a form's user input?Answer: You can either put an onblur event handler on each input field (text input, radio buttons, check boxes, select lists) which will get triggered each time a user leaves any field. This is useful if there are many input fields on the screen that can be evaluated independently.If you either have only a few fields or if some of the fields' rules depend on other fields, then you might prefer to validate upon submission of the form. Use the form's onsubmit event for that as the following example shows. If the validation fails (user puts in an age under 18) then the data does not get posted and the form stays.
Comments:
|