我已经制作了一个简单的表单,其中包含一个是和一个否复选框,我想要它,以便当我按下是时它在警报框中显示 5,当我按下否时它显示 0 但目前当我点击提交时它会出现 [警告框中的对象 htmlDivElement]。
<script>
function alertprice() { // this will be called on submit of the form
alert (runningtotal); // alert the value in variable running total
}
function totalprice () { // function totalprice will set runningtotal depending on boxes ticked
if(document.getElementById('ramyes').checked) {
var runningtotal = "5"
return runningtotal;
}else if(document.getElementById('ramno').checked) {
var runningtotal = "0"
return runningtotal;
}
}
</script>
和html
<form name="theForm" action="shop.html" method="post" onSubmit="checkWholeForm(theForm); return alertprice()">
<h2>Upgrade RAM to "4GB-Kit GEIL Evo One PC3-12800 DDR3-1600 CL9"?</h2>
<h3>
<input type="radio" name="ram" value="yes" id="ramyes">yes<br>
<input type="radio" name="ram" value="no" id="ramno">no
</h3>