Hello,
I have a form and depending on what checkboxes are selected in the form, it loads a custom thank you page when the form is submited. No problem with this. The problem is that the form loads the thank you page BEFORE the form validating function is completed. How do I fix that? Example below:
***HTML form
<form action=”my cgi script” name=”example” method=”post” onsubmit=”return validate(this)”>
Boring form data, checkboxes and text fields.
<input type=”submit” onclick=”redirect(this.form,’group1′)” value=”example” name=”example” />
*** Close HTML form
***Javascript
function validate(form) {
Many, boring, validation functions
}
function redirect (form, group) {
var numberClicked = [];
for (var i=0; i<form.elements.length; i++) {
if (form.elements[i].name == group && form.elements[i].type == ‘checkbox’ && form.elements[i].checked)
numberClicked.push(i);
}
var min=Math.min.apply(Math, numberClicked)+1;
var max=Math.max.apply(Math, numberClicked)+1;
location.href=min+”-“+max+”.htm”
}
***Close Javascript
Thanks!