<!--below is the text boxes which the user will use to define the amount of copies that they need -->
Chapter 1 - Please enter how many copies you would like <br>
<input class="textbox"type="Number" maxlength="24" id="ch1" placeholder="0"><br><br>
Chapter 2 - Please enter how many copies you would like <br>
<input class="textbox"type="text" maxlength="24" id="ch2" placeholder="0"><br><br>
Chapter 3 - Please enter how many copies you would like <br>
<input class="textbox"type="text" maxlength="24" id="ch3" placeholder="0"><br><br>
Chapter 4 - Please enter how many copies you would like <br>
<input class="textbox"type="text" maxlength="24" id="ch4" placeholder="0"><br><br>
Chapter 5 - Please enter how many copies you would like <br>
<input class="textbox"type="text" maxlength="24" id="ch5" placeholder="0"><br><br>
Entire Book - PDF <br>
<input class="textbox"type="text" maxlength="24" id="ebk" placeholder="0"><br><br>
Entire Book - Printed <br>
<input class="textbox"type="text" maxlength="24" id="prnt" placeholder="0"><br><br>
<b> Total : <output id = "total"> 0 </output></b><br>
<b> Postage : <output id = "postage"> 0 </output></b><br>
<b> Grand Total : <output id = "grandtotal"> 0 </output></b><br>
<!-- below is a button which calls the javascript file -->
<input type="button" value="Calculate" id="calcu" onclick="calc()">
<br><br>
<button type="submit">Payment</button>
<script type="text/javascript">
function calc(){
var ch1 = document.getElementById("ch1").value;
var ch2 = document.getElementById("ch2").value;
var ch3 = document.getElementById("ch3").value;
var ch4 = document.getElementById("ch4").value;
var ch5 = document.getElementById("ch5").value;
var tot = document.getElementById("total");
var post = document.getElementById("postage");
var ebk = document.getElementById("bk1").value;
var prnt = document.getElementById("prnt").value;
tot = (Number(ch1) + Number(ch2) + Number(ch3) + Number(ch4) + Number(ch5)) * 2;
if (prnt.value > = 0) {
tot = Number(ebk) * 8;
}
document.getElementById("total").innerHTML = tot;
}
</script>
答案 0 :(得分:0)
这应该有效:
var x = 10;
x += 5;
这将导致15。