Hi,
The following code validates the first select box but then the form still submits - can anyone tell me why
The following code validates the first select box but then the form still submits - can anyone tell me why
Code:
<script type="text/javascript">
function ew_ValidateForm(fobj) {
if (fobj.a_confirm && fobj.a_confirm.value == "F")
return true;
var i, elm, aelm, infix;
var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
for (i=0; i<rowcnt; i++) {
infix = (fobj.key_count) ? String(i+1) : "";
elm = fobj.elements["x" + infix + "_modelid"];
if (elm && !ew_HasValue(elm)) {
if (!ew_OnError(elm, "Please select model..."))
return false;
}
elm = fobj.elements["x" + infix + "_doorsid"];
if (elm && !ew_HasValue(elm)) {
if (!ew_OnError(elm, "Please select bodystyle..."))
return false;
}
elm = fobj.elements["x" + infix + "_specid"];
if (elm && !ew_HasValue(elm)) {
if (!ew_OnError(elm, "Please select spec..."))
return false;
}
elm = fobj.elements["x" + infix + "_engineid"];
if (elm && !ew_HasValue(elm)) {
if (!ew_OnError(elm, "Please select engine variant..."))
return false;
}
}
return true;
}
function submitit(formvar)
{
if (!ew_ValidateForm(formvar)) return false;
formvar.x_action.value='calcRED';
formvar.submit();
return true;
}
</script>
<form name="form1" id="form1" action="form1.asp" method="post" style="margin:0">
<select id='x_modelid' name='x_modelid'>
<option value="" selected>
Model
</option>
</select>
<select id='x_doorsid' name='x_doorsid'>
<option value="" selected>
Doors
</option>
</select>
<select id='x_specid' name='x_specid'>
<option value="" selected>
Spec
</option>
</select>
<select id='x_engineid' name='x_engineid'>
<option value="" selected>
Engine
</option>
</select>
<input type="image" onClick="submitit(this);" src="images/submit.gif" border="0" width="56" height="30" />
</form>