levyuk
asked on
Problems with onSubmit
Hey guys I have a problem with the onSumbit event of my form which used to work correctly. Heres the code
onSubmit="return validateOnSubmit()"
function validateOnSubmit(){
var errors = 0;
if (!document.forms.addClub.c ounty){
return false;
}else{
if (!validateEmail(document.f orms.addCl ub.email, 'inf_email')) errors += 1;
if (!isURL(document.forms.add Club.webSi te,'inf_we bsite')) errors += 1;
if (!validateTelnr(document.f orms.addCl ub.telepho neNo,'inf_ phone', true)) errors += 1;
if (!validateMenu(document.fo rms.addClu b.county, 'inf_county')) errors += 1;
if (!validatePresent(document .forms.add Club.cityT own,'inf_c ity')) errors += 1;
if (!validatePresent(document .forms.add Club.clubA ddress,'in f_address' )) errors += 1;
if (!validateMenu(document.fo rms.addClu b.country, 'inf_country')) errors += 1;
if (!validateMenu(document.fo rms.addClu b.activity , 'inf_activity')) errors += 1;
if (!validatePresent(document .forms.add Club.motiv atingMateI D,'inf_mat eID')) errors += 1;
if (!validatePresent(document .forms.add Club.nameo fclub,'inf _name')) errors += 1;
if (!validateCheckbox(documen t.forms.ad dClub.tand c, 'inf_tandc')) errors += 1;
return (errors == 0);
}
}
each function within the validateOnSubmit() function works fine for each form element when their onchange event fires so I know the functions work i.e. isURL, validateMenu etc. So I don't understand why if one of the inputs is incorrect the form will still submit. ANyone have any ideaS?
onSubmit="return validateOnSubmit()"
function validateOnSubmit(){
var errors = 0;
if (!document.forms.addClub.c
return false;
}else{
if (!validateEmail(document.f
if (!isURL(document.forms.add
if (!validateTelnr(document.f
if (!validateMenu(document.fo
if (!validatePresent(document
if (!validatePresent(document
if (!validateMenu(document.fo
if (!validateMenu(document.fo
if (!validatePresent(document
if (!validatePresent(document
if (!validateCheckbox(documen
return (errors == 0);
}
}
each function within the validateOnSubmit() function works fine for each form element when their onchange event fires so I know the functions work i.e. isURL, validateMenu etc. So I don't understand why if one of the inputs is incorrect the form will still submit. ANyone have any ideaS?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok cool ill try those. Is there any reason why my code shouldn't work?
Hi levyuk
1. Can you post here how you call the function for individual form elements i.e. onchange="....."
2. Have you written form tag like this
<form name="addClub" onSubmit="return validateOnSubmit()"> or <form id="addClub" onSubmit="return validateOnSubmit()">
By Nab
1. Can you post here how you call the function for individual form elements i.e. onchange="....."
2. Have you written form tag like this
<form name="addClub" onSubmit="return validateOnSubmit()"> or <form id="addClub" onSubmit="return validateOnSubmit()">
By Nab
ASKER
Form:
<form class="form" onSubmit="return validateOnSubmit()" style="width:100%" method="post" name="addClub" action="processClub.php">
Elements:
<input class="form" type="text" name="nameofclub" id="nameofclub" onChange="validatePresent( this, 'inf_name');">
<form class="form" onSubmit="return validateOnSubmit()" style="width:100%" method="post" name="addClub" action="processClub.php">
Elements:
<input class="form" type="text" name="nameofclub" id="nameofclub" onChange="validatePresent(
ASKER
I found the problem, was a bloody copy/paste error of mine. Cheers for your help, you can have points for helping me even though the answer isn't there.
Thanks
J
Thanks
J
Sorry I think addclub is your form name so try this
function validateOnSubmit(){
var errors = 0;
if (!document.addClub.county)
return false;
}else{
if (!validateEmail(document.a
if (!isURL(document.addClub.w
if (!validateTelnr(document.a
if (!validateMenu(document.ad
if (!validatePresent(document
if (!validatePresent(document
if (!validateMenu(document.ad
if (!validateMenu(document.ad
if (!validatePresent(document
if (!validatePresent(document
if (!validateCheckbox(documen
if (errors == 0)
{
return true;
}
else
{
return false;
}
}
}
OR
function validateOnSubmit(){
var errors = 0;
if (!document.forms[0].county
return false;
}else{
if (!validateEmail(document.f
if (!isURL(document.forms[0].
if (!validateTelnr(document.f
if (!validateMenu(document.fo
if (!validatePresent(document
if (!validatePresent(document
if (!validateMenu(document.fo
if (!validateMenu(document.fo
if (!validatePresent(document
if (!validatePresent(document
if (!validateCheckbox(documen
if (errors == 0)
{
return true;
}
else
{
return false;
}
}
}
By Nab