Interview Questions

How can I require that fields be filled in, or filled in correctly?

HTML Interview Questions and Answers


(Continued from previous question...)

40. How can I require that fields be filled in, or filled in correctly?

Have the server-side (e.g., CGI) program that processes the form submission send an error message if the field is not filled in properly. Ideally, this error message should include a copy of the original form with the original (incomplete or incorrect) data filled in as the default values for the form fields. The Perl CGI.pm module provides helpful mechanisms for returning partially completed forms to the user.
In addition, you could use JavaScript in the form's ONSUBMIT attribute to check the form data. If JavaScript support is enabled, then the ONSUBMIT event handler can inform the user of the problem and return false to prevent the form from being submitted.
Note that the server-side program should not rely upon the checking done by the client-side script.

(Continued on next question...)

Other Interview Questions