Force
07-23-2003, 09:08 AM
I'm trying to use the following code to validate a form upon submission. The first two fields that I validated worked fine. When I added the last field to validate I messed something up, because it blows right through the validation, even if one of the first two is missing.
I think it's something in how I'm nesting the else statements, but I can't find the fix. I want to add numerous else statements to this.
I appeciate the help. Thanks.
<script language="JavaScript">
function doublecheck(){
if (document.myform.fname.value == "")
{
alert('First Name is a required field');
myform.fname.focus();
myform.fname.select();
return false;
}else{
if (document.myform.lname.value == "")
{
alert('Last Name is a required field');
myform.lname.focus();
myform.lname.select();
return false;
}
}else{
if (document.myform.phone.value == "")
{
alert('Phone is a required field');
myform.phone.focus();
myform.phone.select();
return false;
}
}
}
</script>
I think it's something in how I'm nesting the else statements, but I can't find the fix. I want to add numerous else statements to this.
I appeciate the help. Thanks.
<script language="JavaScript">
function doublecheck(){
if (document.myform.fname.value == "")
{
alert('First Name is a required field');
myform.fname.focus();
myform.fname.select();
return false;
}else{
if (document.myform.lname.value == "")
{
alert('Last Name is a required field');
myform.lname.focus();
myform.lname.select();
return false;
}
}else{
if (document.myform.phone.value == "")
{
alert('Phone is a required field');
myform.phone.focus();
myform.phone.select();
return false;
}
}
}
</script>