我是javascript的新手我尝试根据发货国家/地区编码货币变更条件,但在所有情况下都会出错。
条件
帮我纠正错误。
提前致谢。
<script>
function submitFunction() {
var country=document.getElementById("location");
var currency=document.getElementById("money");
if (country =='India' && currency =='INR'){
window.location.assign("thanks.html");
} else if (country =='India' && currency !='INR') {
alert("Change the currency as Indian Rupee");
} else if (country !='India' && currency =='INR') {
alert("Change the currency as other than Indian Rupee");
} else {
window.location.assign("thanks.html");
}
}
</script>
</head>
<body>
<div id="navMainSearch" style="height: 50px; margin-top:
18px; margin-bottom: -15px;">
<form method="get" action="" name="currencies">
<select id="money" onchange="" name="currency" >
<option value="USD">US Dollar</option>
<option value="EUR">Euro</option>
<option value="GBP">British Pound Sterling</option>
<option value="CAD">Canadian Dollar</option>
<option value="AUD">Australian Dollar</option>
<option selected="selected" value="INR">Indian
Rupees</option>
</select>
<input type="hidden" value="checkout" name="main_page">
<input type="hidden" name="fecaction">
</form>
</div>
<div id="checkoutShipto" class="floatingBox back">
<address class="checkoutAddress">
Raja
<br>
423, Vinayagar Kovil Street
<br>
Chennai, 600027
<br>
TN,India<div id="location">India</div>
</address>
</div>
<div class="buttonRow forward">
<input type="submit" onclick="submitFunction()" title="Confirm Order " alt="Confirm Order" value="submit" act >
</div>
</div>
答案 0 :(得分:0)
您的货币是选择对象,而不是值。要获取选择控件的值,您可以使用此代码
var money = document.getElementById("money");
var currency = money.options[money.selectedIndex].value;
对于国家/地区,您应该使用
var country = document.getElementById("location").innerText;