Cut & Paste Check required elements
Example: Below is a sample form. Try filling out different elements, and submitting it. All "required" elements have to be filled before submission is allowed.
Sample form: (* required elements)
Step 1: Insert the below into the <head> section of your page:
Step 2: Add the following inside the <form> tag of the form you wish to validate:
<form onSubmit="return checkrequired(this)">
Specifying required elements: Now, to mark an element inside the form as "required", simply prefix the element's name with the keyword "required". Uh? For example, using the above example, the source code looks something like this:
<input type="text" name="requiredname">
<input type="text" name="requiredemail">
Notice how the names of all of the required elements have one thing in common- their names have the prefix "required". This indicates to the script that those are elements that have to have input in them. For either text or textarea elements, this means they have to contain some text; for selection list, this means at least one selection has to be selected.
Note: Due to the "optional" nature of check and radio boxes, this script cannot be used to mark those elements as required (giving check or radio boxes a "required" prefix will do nothing).