当我在Update_Price
标记上进行任何更改时,我尝试访问JavaScript文件中的select
函数,但遗憾的是显示了未捕获的参考错误。这是我的代码:
<!Doctype html>
<html>
<head>
<script type="text/javascript" src="Form-validation.js"></script>
</script>
</head>
<body>
<select class="Booking-Form-Group" id="combo-box" onchange="Update_Price()">
<option value="1">Single Room</option>
<option value="2">Double Room</option>
<option value="3">Twin Room </option>
<option value="4">Family Room</option>
<option value="5">Standard Room</option>
<option value="6">Meeting Hall</option>
<option value="7">Conference Room</option>
</select>
</body>
</html>
这是我的JavaScript代码。
function Update_Price(){
alert('Warning');
var combo = document.getElementById('combo-box');
var index = combo.options[combo.selectedIndex].value;
var value = 0;
if (index == 1){
value = 15;
}
else if(index == 2 || index == 3){
value = 25;
}
else if(index == 4){
value = 40;
}
else if(index == 5){
value = 20;
}
else{
value = 60;
}
alert(value);
document.getElementById('price').innerHTML='Total Price is: '.value;
}
答案 0 :(得分:3)
你的问题就在这一行
document.getElementById('price').innerHTML='Total Price is: '.value;
它应该有一个连接运算符+
而不是.
document.getElementById('price').innerHTML='Total Price is: ' + value;