I have made a simple form with a yes and a no checkbox for ram, i want it so that when i press yes it says 5 in an alertbox, and when i press no it says 0 but currently when i hit submit it comes up [Object htmlDivElement] in the alertbox.
<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>
and the 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>
You have to call your function totalprice(). For example like this: