我对javascript很新,所以对某些人来说这可能很容易。我试图根据访问者是否选择选项" 0到120,000"来生成感谢信息。 AND "选项0到6个月"。非常感谢任何帮助。
function redirect() {
var businessrev = document.getElementById("annual_business_revenue");
var time = document.getElementById("Time")
for (var i = 0; i < selections.options.length; i++) {
if ((businessrev.options[i].selected == 1) && (time.options[i].selected == 1)) {
location.href = "http://www.bing.com";
} else {
location.href = "http://www.google.com";
}
}
}
&#13;
<form action="javascript:redirect();">
<select name="annual_business_revenue">
<option value="revenue1">0 to 120,000</option>
<option value="revenue2">NOT 0 to 120,000</option>
</select>
<select name="Time">
<option value="time1">0 to 6months</option>
<option value="time2">NOT 0 to 6months</option>
</select>
<input type="submit" value="Submit" />
</form>
&#13;
答案 0 :(得分:0)
使用它。希望它会有所帮助。
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
function abc() {
var businessrev = document.getElementById("annual_business_revenue");
var time = document.getElementById("Time");
if((businessrev.selectedIndex=="0") && (time.selectedIndex =="0"))
location.href = "http://www.bing.com";
else
location.href = "http://www.w3schools.com/";
return false;
}
</script>
<form onsubmit="return abc()">
<select id="annual_business_revenue">
<option value="revenue1">0 to 120,000</option>
<option value="revenue2">NOT 0 to 120,000</option>
</select>
<select id="Time">
<option value="time1">0 to 6months</option>
<option value="time2">NOT 0 to 6months</option>
</select>
<input type="submit" value="Submit" />
</form>
</body>
</html>
答案 1 :(得分:0)
我建议使用此版本
window.onload=function() {
document.getElementById("goBut").onclick=function() {
var businessrev = document.getElementById("annual_business_revenue").value;
var time = document.getElementById("Time").value;
if (businessrev=="revenue1" && time=="time1") {
alert("Great choice");
location.href = "http://www.bing.com";
} else {
location.href = "http://www.google.com";
}
}
}
<select id="annual_business_revenue">
<option value="revenue1">0 to 120,000</option>
<option value="revenue2">NOT 0 to 120,000</option>
</select>
<select id="Time">
<option value="time1">0 to 6months</option>
<option value="time2">NOT 0 to 6months</option>
</select>
<input id="goBut" type="button" value="Submit" />
要修复你的POSTED版本,你需要在我写一个更好的版本之前做我在第一条评论中建议的内容:
function redirect() {
var businessrev = document.getElementById("annual_business_revenue"),
time = document.getElementById("Time");
if (businessrev.selectedIndex == 0 && time.selectedIndex == 0) {
alert("Good choice");
location.href = "http://www.bing.com";
} else {
location.href = "http://www.google.com";
}
return false; // cancel submit
}
<form onsubmit="return redirect();">
<select id="annual_business_revenue">
<option value="revenue1">0 to 120,000</option>
<option value="revenue2">NOT 0 to 120,000</option>
</select>
<select id="Time">
<option value="time1">0 to 6months</option>
<option value="time2">NOT 0 to 6months</option>
</select>
<input type="submit" value="Submit" />
</form>
使用表单:
window.onload=function() {
document.getElementById("pardot-form").onsubmit=function() {
var businessrev = this.elements[1], // second form element
time = this.elements[2]; // third
if (businessrev.selectedIndex == 1 && time.selectedIndex == 1) { // first choice
alert("Good choice");
}
}
}
<form id="pardot-form">
<input type="text" name="emial"/>
<select>
<option value="">Please select</option>
<option value="revenue1">0 to 120,000</option>
<option value="revenue2">NOT 0 to 120,000</option>
</select>
<select>
<option value="">Please select</option>
<option value="time1">0 to 6months</option>
<option value="time2">NOT 0 to 6months</option>
</select>
<input type="submit" value="Submit" />
</form>
答案 2 :(得分:0)
这对我有用:
window.onload=function(){
var annualRevenue = 'annual_business_revenue';
var email = 'email';
var timeInBusiness = 'Time';
if((timeInBusiness == '0 to 6months' || annualRevenue == '0 to 120,000' )){
document.location='http://google.com';
}else{
document.location='http://bing.com';
}
};
<select id="annual_business_revenue">
<option value="revenue1">0 to 120,000</option>
<option value="revenue2">NOT 0 to 120,000</option>
</select>
<select id="Time">
<option value="time1">0 to 6months</option>
<option value="time2">NOT 0 to 6months</option>
</select>
<input id="goBut" type="button" value="Submit" />