PDA

View Full Version : Javascript form validation help



rmgoodm
02-18-2009, 07:45 PM
I am 95% there, but since I am not a Javascript or web developer by trade, I couldn't beat this into submission. Any help would be greatly appreciated.

I have this simple script that evaluates text input fields and a checkbox that someone must check before proceeding. "agreement" is the checkbox name/id. I have this working without any problems when I use text fields but when I introduce the checkbox it does not seem to work.

Any help is greatly appreciated! Thanks in advance.


<form onsubmit="return checkForm(this)">
<input name="agreement" type="checkbox" id="agreement" value="1" />
...
</form>

<script type="text/javascript">
function checkForm(frm){
msg = "";

if(!frm.first_name.value){
msg += "- First name is required\n";
}

if(!frm.agreement.value){
msg += "- Accept the terms of use\n";

}

if(msg != ""){
alert(msg);
return false;
}
}
</script>

trochia
02-21-2009, 01:41 PM
From my understanding, you would just like to make this 'required' before processing? Is this just a simple e-mail form?

http://www.elated.com/articles/form-validation-with-javascript/