/* hw4b.js */
window.onload = function(){
/*-------------------------------------------------------------------------------------------------
SET DEFAULT FOCUS TO USER NAME for EXTRA CREDIT
-------------------------------------------------------------------------------------------------*/
/*function setFocusToUserName(){
document.getElementById("username").focus();
}*/
function setFocusToTextBox( _element ) {
document.forms[ 'hw4Form' ].elements[ _element ].focus();
}
setFocusToTextBox( 1 );
// sets focus on second element (username) of the form
/*-------------------------------------------------------------------------------------------------
PASSWORD FIELDS VALIDATION #1
-------------------------------------------------------------------------------------------------*/
var pwd1 = document.getElementById("pwd1");
var pwd2 = document.getElementById("pwd2");
//var success = "#66cc66";
pwd1.addEventListener("keyup", function(){
// pwd1 must have at least 8 characters
if (pwd1.value.length < 8) {
pwd1Hint.setAttribute('class', 'red');
pwd1Hint.innerHTML = "Your password must be at least 8 characters.";
}
// success
if (pwd1.value.length >= 8) {
//pwd1Hint.setAttribute('class', 'pass');
pwd1Hint.innerHTML = "";
}
});
pwd2.addEventListener("keyup", function(){
// compare the values in the password fields
if(pwd1.value != pwd2.value){
//The passwords do not match
pwd2Hint.setAttribute('class', 'red');
pwd2Hint.innerHTML = "Your passwords must match";
} else {
//The passwords match
//pwd2Hint.setAttribute('class', 'pass');
pwd2Hint.innerHTML = "";
}
});
/*-------------------------------------------------------------------------------------------------
COUNTING CHARACTERS MAX OF 140 IN BIO TEXT BOX #2
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.