I have a form that has two textfields, one password field, one email field, three radio buttons, and three check boxes. What I'm trying to accomplish is that if someone doesn't enter the a specific amount into the textfields, or doesn't give enough characters for the password, or fails to select a radio button, a little error will pop up next to it saying something like "This field must have two of more characters".
HTML:
Text Field: <input type="text" name="fName" id="textField" /></br></br>
Number Field: <input type="text" name="lName" id="numField" /></br></br>
Email: <input type="email" name="email" id="email" /></br></br>
Password: <input type="password" name="pWord" id="passWord" /></br></br>
<input type="radio" name="click" value="radio1" id="rad1"> Radio 1</br>
<input type="radio" name="click" value="radio2" id="rad2"> Radio 2</br>
<input type="radio" name="click" value="radio3" id="rad3"> Radio 3</br>
</br>
<input type="checkbox" name="vehicle" value="bike" id="bike">Bike</br>
<input type="checkbox" name="vehicle" value="motorcycle" id="mCycle">Motorcycle</br>
<input type="checkbox" name="vehicle" value="car" id="car">Car/Pickup</br>
<input type="checkbox" name="vehicle" value="public" id="public">Public (Bus/Train)
I have no working script for this yet because I haven't been able to figure it out, but what I've attempted would be something like:
if($('#textField').length < 2) {
$( "#textField" ).after('<span id="txt1">Must be atleast 2 characters</span>');
}
The errors should throw next to the fields, so:
- text field = must be 2 characters.
- number field = must be 2 characters.
- email = must be email.
- password = must be 5 characters.
- three radio button - must select one button
- three checkboxes - must select one checkbox