我只想要一个简单的程序来计算插入select标签中的预定义值并将其乘以文本框的值(也将转换为整数)并将其打印在“prod”文本框中。
<script type="text/javascript">
//num2 is the id of my select tag
var index = document.getElementById("num2").selectedIndex;
//num1 is the id of my textbox
//prod is the id of product textbox
function mul(){
var a = parseInt(document.getElementById("num1").value);
var b = document.getElementById("num2").value;
var c = document.getElementById("prod").value;
c.value=(a*b);
}
</script>
我疯了......
答案 0 :(得分:0)
@bloodyKnuckles是正确的,var b
需要等于元素,而不是元素的value属性。
答案 1 :(得分:0)
您必须获取值并使用parseInt()
将其转换为字符串中的整数:
parseInt(document.getElementById("first").value) + parseInt(document.getElementById("second").value);
答案 2 :(得分:0)
//num2 is the id of my select tag
var index = document.getElementById("num2").selectedIndex;
//num1 is the id of my textbox
//prod is the id of product textbox
function mul() {
debugger
var a = parseInt(document.getElementById("num1").value);
var b = document.getElementById("num2").value;
var c = document.getElementById("prod");
c.value = (a * b);
}