PDA

View Full Version : Validating text in a form


blackeye
03-08-2009, 10:34 AM
Hello,
I have a form setup in a HTML document that is used to collect the persons information such as first name, last name, address and etc. How do I go about getting javascript to pop up a alert box and put the cursor in the box that is left blank when the user clicks on the submit button if a field has been left blank? Also if all the forms have been filled out than it displays a message stating "Thanks for updating your information".
What would the code look like, I have 8 text box fields that I need to validate put I don't quite know what the code looks like. This is what i have so far but I think I'm wrong.

Thanks,

function chkPasswrods() {
var init = document.getElementById("initial");
var sec = document.getElementById("second");
if (init.value == "") {
alert("You did not enter a password \n" +
"Please enter one now");
init.focus();
return false;
}
if (init.value != sec.value) {
alert("The two passwords you entered are not the same \n" +
"Please re-enter both now");
init.focus();
init.select();
return false;
} else
return true;
}

omnicity
03-09-2009, 08:07 AM
That looks like it should work - only question I have is how are you calling it?
Do you get any errors?