基于表单中的下拉答案的多个重定向



我正在努力寻找这个问题的答案,并尝试了一些事情,但我希望有人能帮助我。我有一个登陆页的形式,重定向提交到一个取消资格的感谢页面,如果领导回答错误的问题之一。我知道我的代码在大多数情况下都能很好地工作,但其中一个问题有多个答案,这将取消一个潜在客户的资格,只有当他们选择一个选项而不是另一个选项时,它才会取消资格,这也会取消那个人的资格。

例如,我们有一个下拉选项,让您选择您的年龄范围。如果你选择"30-49"它需要取消这个人的资格,目前它是这样做的,但我也需要它取消那些选择"65岁及以上"的人的资格;也现在,如果他们选择"30-49",它会被重定向到我们的取消资格页面。但如果他们选择"65岁及以上",它不会重定向。我需要它两者兼顾。

我试过添加AND&&标签,而不是OR||标签,但我仍然在努力让它工作。任何帮助,这将是非常感激。提前感谢!

<script> 

function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}

var months_12 = getUrlVars()["months_12"];
var doctor_care = getUrlVars()["doctor_care"];
var current_benefits = getUrlVars()["current_benefits"];
var have_attorney = getUrlVars()["have_attorney"];
var first_name = getUrlVars()["first_name"];
var last_name = getUrlVars()["last_name"];
var age = getUrlVars()["age"];
var email = getUrlVars()["email"];
var phone_number = getUrlVars()["phone_number"];

var redirect_url = '';
if (months_12 == "No" || doctor_care == "No" || current_benefits == "Yes" || have_attorney == "Yes" || age == "30-49" || age == "65 and over") {
redirect_url = "http://unbouncepages.com/mblsdd-thank-you-3/?"; 
} 
else {
redirect_url = "http://unbouncepages.com/mblssd-thank-you-5/?";
}

redirect_url = redirect_url+"months_12="+months_12+"&doctor_care="+doctor_care+"&current_benefits="+current_benefits+"&have_attorney="+have_attorney+"&age="+age+"&first_name="+first_name+"&last_name="+last_name+"&email="+email+"&phone_number="+phone_number;

window.location.href = redirect_url;


</script>

大多数现代浏览器中的查询字符串将自动被encodeURI()编辑。这意味着您必须decodeURI()查询字符串值。此外,您不需要为所需的每个键/值对调用queryString()函数。例:

function queryString()
{
let vars = {};
let parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value)
{
vars[key] = decodeURI(value);
});
return vars;
}

const queryArray = queryString();
let months_12 = queryArray["months_12"];
let doctor_care = queryArray["doctor_care"];
let current_benefits = queryArray["current_benefits"];
let have_attorney = queryArray["have_attorney"];
let first_name = queryArray["first_name"];
let last_name = queryArray["last_name"];
let age = queryArray["age"];
let email = queryArray["email"];
let phone_number = queryArray["phone_number"];
let redirect_url = "";
if(months_12 == "No" || doctor_care == "No" || current_benefits == "Yes" || have_attorney == "Yes" || age == "30-49" || age == "65 and over") {
redirect_url = "http://unbouncepages.com/mblsdd-thank-you-3/?"; 
} 
else {
redirect_url = "http://unbouncepages.com/mblssd-thank-you-5/?";
}
redirect_url = redirect_url+"months_12="+months_12+"&doctor_care="+doctor_care+"&current_benefits="+current_benefits+"&have_attorney="+have_attorney+"&age="+age+"&first_name="+first_name+"&last_name="+last_name+"&email="+email+"&phone_number="+phone_number;

window.location.href = redirect_url;

如果你试图获取一个不存在的键的值,那么你将得到'undefined'。

最新更新