我正在处理此表单选择条件,该条件将在单击提交按钮时加载特定页面。现在我收到windows.location
的意外令牌错误。所有文件都在同一个文件夹中
<script>
$(document).ready(function() {
$("#process_app").submit(function() {
var selrange = $("select#range").val();
var selplace = $("select#place").val();
var selindustry = $("select#industry").val();
if (selrange = '1') {
// if value 1 load US short app, if value 2 load Canada short app
window.location = selplace = "1" ? 'application_us_short.php' : 'application_ca_short.php');
}
if ((selrange = '2') && (selindustry = '2' || selindustry = '10')) {
window.location = selplace = "1" ? 'application_us_short.php' : 'application_ca_short.php');
}
if ((selrange = '2') && (selindustry != '2' || selindustry != '10') || selrange = '3') {
window.location = selplace = "1" ? 'application_us.php' : 'application_ca.php');
}
});
});
</script>
<div style="margin: 0 auto; text-align: center; margin-top: 60px">
<form id="app_type">
<h4>What country are you located in?</h4>
<select id="place" name="place" onchange="location = this.options[this.selectedIndex].value;">
<option value="1">United States</option>
<option value="2">Canada</option>
</select>
<h4>What industry is your company most closely associated with?</h4>
<select id="industry" name="industry" onchange="location = this.options[this.selectedIndex].value;">
<option value="1">Agriculture</option>
<option value="2">Consumer Electronics & Appliances</option>
<option value="3">Construction/Industrial</option>
<option value="4">Manufactured Housing</option>
<option value="5">Marine</option>
<option value="6">Music</option>
<option value="7">Outdoor Power Equipment</option>
<option value="8">Power Sports</option>
<option value="9">Recreational Vehicles</option>
<option value="10">Technology</option>
<option value="11">Trailer</option>
</select>
<h4>What credit line range are you applying for?</h4>
<select id="range" name="range" onchange="location = this.options[this.selectedIndex].value;">
<option value="1">Less than $150,000</option>
<option value="2">$150,001-$350,000</option>
<option value="3">$350,000+</option>
</select>
<hr>
<input type="submit" value="Submit" id="process_app" />
</form>
</div>
答案 0 :(得分:1)
您正在分配值而不是比较
selplace = "1"
试试这个
selplace == "1"
答案 1 :(得分:0)
您正在分配值而不是检查它
您的代码
window.location = selplace = "1" ? 'application_us_short.php' : 'application_ca_short.php');
建议的更改
window.location = selplace === "1" ? 'application_us_short.php' : 'application_ca_short.php');
有关详细信息,请访问 Which equals operator (== vs ===) should be used in JavaScript comparisons?
答案 2 :(得分:0)
试试这个,然后在if语句中更改括号
$(document).ready(function() {
$("#app_type").submit(function() {
var selrange = $("select#range").val();
var selplace = $("select#place").val();
var selindustry = $("select#industry").val();
if (selrange == '1') {
// if value 1 load US short app, if value 2 load Canada short app
window.location = selplace = "1" ? 'application_us_short.php' : 'application_ca_short.php';
}
if ((selrange == '2') && (selindustry == '2' || selindustry == '10')) {
window.location = selplace = "1" ? 'application_us_short.php' : 'application_ca_short.php';
}
if ((selrange == '2') && (selindustry != '2' || selindustry != '10') || (selrange = '3')) {
window.location = selplace = "1" ? 'application_us.php' : 'application_ca.php';
}
alert(window.location);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>
<div style="margin: 0 auto; text-align: center; margin-top: 60px">
<form id="app_type">
<h4>What country are you located in?</h4>
<select id="place" name="place" onchange="location = this.options[this.selectedIndex].value;">
<option value="1">United States</option>
<option value="2">Canada</option>
</select>
<h4>What industry is your company most closely associated with?</h4>
<select id="industry" name="industry" onchange="location = this.options[this.selectedIndex].value;">
<option value="1">Agriculture</option>
<option value="2">Consumer Electronics & Appliances</option>
<option value="3">Construction/Industrial</option>
<option value="4">Manufactured Housing</option>
<option value="5">Marine</option>
<option value="6">Music</option>
<option value="7">Outdoor Power Equipment</option>
<option value="8">Power Sports</option>
<option value="9">Recreational Vehicles</option>
<option value="10">Technology</option>
<option value="11">Trailer</option>
</select>
<h4>What credit line range are you applying for?</h4>
<select id="range" name="range" onchange="location = this.options[this.selectedIndex].value;">
<option value="1">Less than $150,000</option>
<option value="2">$150,001-$350,000</option>
<option value="3">$350,000+</option>
</select>
<hr>
<input type="submit" value="Submit" id="process_app" />
</form>
</div>
答案 3 :(得分:0)
window.location
无效,因为您要为selrange
(selrange = '1'
,selrange = '2'
)分配一个值,而不是比较该值,请替换为selrange == '1' ,selrange == '2'