I've been fooling around with this function and I'm trying to get it to work. Maybe one of you guys can put me back on track. So right below here is the function. I've been trying lots of things to get this to work so it might look a little messy.
function validation(form1)
{
if (form1.first_name.value == '')
{
document.form1.getElements
ByName("fi
rst_name_e
rror").val
ue = "*Missing first name";
return false;
}
if (form1.last_name.value == '')
{
document.form1.getElements
ByName("la
st_name_er
ror").valu
e = "*Missing last name";
return false;
}
if (form1.company.value == '')
{
document.form1.getElements
ByName("co
mpany_erro
r").value = "*Missing company name";
return false;
}
if (form1.email.value != '')
{
document.form1.getElements
ByName("em
ail_error"
).value = "*Missing email address";
return false;
}
if (form.first_name.value != '' && form.last_name.value != ''
&& form.company.value != '' && form.email.value != '')
{
return true;
}
return false;
}
</script>
This is what I'm using to call it.
--------------------------
----------
---
<html>
<form action="servlet URL" method="post" onsubmit="return validation(this)" />
<body>
<form id="form1" runat="server">
<asp:Button runat="server" text="Register" id="submit" />
<asp:Label id="first_name_error" runat="server" /> // Here is just one of the lables
<body>
</form>
I'm basically trying to make a validation check on input from the user to register for something. I'm trying to avoid using popups. So I have a button that will run a form action that calls a function that will do the validation. Problem is I can't get the code for the validation correct. Any thoughts?
Start Free Trial