M
Matt Herson
I am using the following script given in an earlier post:
<script type="text/javascript">
function validate(form) {
for (var i = 0; i < form.elements.length; i++) {
var elem = form.elements;
if (elem.tagName == "INPUT" &&
(elem.type == "text" || elem.type == "password") ||
elem.tagName == "TEXTAREA") {
if (elem.value == "") {return false;}
}
}
return true;
}
function validateAndDisplay(form,div) {
div = document.getElementById(div);
if (!validate(form)) {
div.innerHTML = "Some fields still needs to be filled.";
return false;
} else {
div.innerHTML = "";
return true;
}
}
</script>
Then in my action I have:
<FORM ACTION="../cgi-bin/CSMailto/CSMailto.cgi" METHOD=POST
enctype="multipart/form-data" onsubmit="validateAndDisplay(this,'output')">
I have these tags preceeding the form:
<div id="output"></div>
And my submit button is:
<input name="B1" type="image" src="../../../images/request_info_submit.gif">
After submitting the form with a missing required field, I am given the
screen with the message and the form (the behavior that I want), then the
screen automatically resubmits the form and goes to another page. Any ideas
why it won't stay on the screen with the message?
Thanks!
-Matt
<script type="text/javascript">
function validate(form) {
for (var i = 0; i < form.elements.length; i++) {
var elem = form.elements;
if (elem.tagName == "INPUT" &&
(elem.type == "text" || elem.type == "password") ||
elem.tagName == "TEXTAREA") {
if (elem.value == "") {return false;}
}
}
return true;
}
function validateAndDisplay(form,div) {
div = document.getElementById(div);
if (!validate(form)) {
div.innerHTML = "Some fields still needs to be filled.";
return false;
} else {
div.innerHTML = "";
return true;
}
}
</script>
Then in my action I have:
<FORM ACTION="../cgi-bin/CSMailto/CSMailto.cgi" METHOD=POST
enctype="multipart/form-data" onsubmit="validateAndDisplay(this,'output')">
I have these tags preceeding the form:
<div id="output"></div>
And my submit button is:
<input name="B1" type="image" src="../../../images/request_info_submit.gif">
After submitting the form with a missing required field, I am given the
screen with the message and the form (the behavior that I want), then the
screen automatically resubmits the form and goes to another page. Any ideas
why it won't stay on the screen with the message?
Thanks!
-Matt