Example Form
Introduction
Adding Validation to a form
- The example form
- Including rsv.js
- Defining your validation rules
- Adding the onsubmit handler
- The finished product
References
Let's start with a simple form that we're going to want to validate. Here's what it looks like, followed by the code.
The HTML Code
<form action="" method="post">
<table class="demoTable" cellpadding="0" cellspacing="1">
<tr>
<th width="150">First Name:</th>
<td><input type="text" name="first_name" /></td>
</tr>
<tr>
<th>Last Name:</th>
<td><input type="text" name="last_name" /></td>
</tr>
<tr>
<th>Email:</th>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<th>Your age:</th>
<td><input type="text" name="any_integer" /></td>
</tr>
<tr>
<th>Marital Status:</th>
<td>
<input type="radio" id="ms1" name="marital_status" value="single" />
<label for="ms1">Single</label><br />
<input type="radio" id="ms2" name="marital_status" value="married" />
<label for="ms2">Married</label><br />
<input type="radio" id="ms3" name="marital_status" value="none_of_your_business" />
<label for="ms3">None of your bloomin' business</label>
</td>
</tr>
</table>
</form>