I am sure this is super easy, but for some reason I just can't figure this one out.
I need to create a form on the page with the following fields and rules. If the user submits a form but the rules are broken for any field, the behavior listed must be done to advise the user. I am not allowed to use jQuery. Field01 & Field02 is one box. Field03 & Field04 is one box.
* Field01: "Username" - Rule01: Cannot be empty, Behavior01: Put focus on it using focus().
* Field02: "Username" - Rule02: Cannot be empty, Behavior02: Alert the user that "username is required".
* Field03: "Birthyear" - Rule03: Must be numeric, Behavior03: Select the value using select().
* Field04: "Birthyear" - Rule04: Must be between 1900 - 2012, Behaviour04: Turn the Birthyear text box background color to yellow.
This is what I have so far... Struggling with the Field03 & Field04.
Does anyone know how to approach this?
JS in Separate file:
document.getElementById("username").focus(); // focus on text box
// focus on text box
return false; // validation failed
return true; // validation success
Take a look at this answer and fiddle for a general outline of how to setup the validation process (sans jQuery).