[英]Uncaught ReferenceError: function is not defined with onchange
I'm trying to access to Update_Price
function in JavaScript file when I make any changing on select
tag, but unfortunately the Uncaught Reference Error appear. 当我在
select
标签上进行任何更改时,我正在尝试访问JavaScript文件中的Update_Price
函数,但遗憾的是出现了Uncaught Reference Error。 This is my code: 这是我的代码:
<!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>
This is my JavaScript code. 这是我的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;
}
Your problem is this line 你的问题是这一行
document.getElementById('price').innerHTML='Total Price is: '.value;
It should have a concatenation operator +
instead of .
它应该有一个连接运算符
+
而不是.
document.getElementById('price').innerHTML='Total Price is: ' + value;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.