White Bar

Validated Form


The following is the source code for a validated form. Insert your desired fields between the "above" and "below" comment tags.




Add your fields between the "above" and "below" comment tags.


Be sure to change the "txtEmailTo" to the email address you want the form to send to. Also change the "txtEmailSubject" to the name or description of the form.


To make the form validate you will need to add the names of the fields you want validated to the JavaScript if/else code at the end of the file like so:

 

if (document.form1.Name.value == "" 

|| document.form1.txtEmailFrom.value == "" 

|| document.form1.NameOfYourFieldHere.value == ""

|| document.form1.NameOfYourFieldHere.value == "" )

 

The double lines "||" mean "or" in JavaScript, so you can add as many required fields as you want. 

To make the required fields yellow, add the following to each open or input tag:
class="req"

 

The above will work if you are using only text, textareas, and select menus. For validating other form fields, Click Here for an off campus guide to validating forms. Copy/paste any of the if statements between the "function required(){" and "}" brackets and before the else{} statement.