PDA

View Full Version : How to: If no message, then redirect



ehooper
08-14-2007, 07:50 PM
I'm not sure if this should be here since its dynamic drive script, but I want to add on, not trouble shoot.

I'm brand new to javascript, so this is killing me. I want the script to run and then if no message is displayed (ie, all the required fields are filled out) THEN it will redirect to thankyou.htm. can someone help me?

My form is already set up so that if all fields are filled in, it will submit the form by email, but I need it to also redirect at the same time. I've tried multiple html/form ways to do this that i've found on the internet, but none have worked (which makes me wonder, because I copied word for word and supposedly the logic is sound) if anyone has another way to do this, that'd be nice too.



<script language="JavaScript">
<!--

/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("Email", "Work Phone", "Company", "Do you want a quote or to order", "Contact Name");
// Enter field description to appear in the dialog box
var fieldDescription = Array("E-mail", "Work Phone", "Company Name", "Quote or Buy", "Contact Name");
// dialog message
var alertMsg = "Please complete the following fields:\n";

var l_Msg = alertMsg.length;

for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";

}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";

}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;

}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";

}
}
}
}

if (alertMsg.length == l_Msg){
return true;

}else{
alert(alertMsg);
return false;


}

}
// -->
</script>
<!-- document.location='thankyou.htm'; -->