My situation is I have just completed an order form and everything works fine with it no problems. Then afterwards I got asked to edit it slightly so it can auto work out the total of the order whilst selecting the different pricing options. The total price will change depending on what boxes are selected so its just basically adding up the values of the checkbox(s) that are selected.
Code that I currently have now is:
Top of page (in header bracket):
<script type="text/javascript" src="autoSumCheckboxes.js"></script>
This is the code for my autoSumCheckboxes.js file:
function UpdateCost() {
var sum = 0;
var ev, elem;
for (i=0; i<3; i++)
{
ev = 'registrationday'+i;
elem = document.getElementById(ev);
if (elem.checked == true) { sum += Number(elem.value); }
}
document.getElementById('totalcost').value = sum.toFixed(2);
}
The html on my order form page is:
<input name="registrationday3" type="checkbox" id="registrationday3" value="55.00" onclick="CheckRegistration56Days();DisplayconfPay3();UpdateCost()"> <input type="checkbox" name="registrationday2" id="registrationday2" value="55.00" onclick="CheckRegistrationDaysBothOption();DisplayconfPay2();UpdateCost()"> <input name="registrationday1" type="checkbox" id="registrationday1" value="55.00" onclick="CheckRegistrationDaysBothOption();DisplayconfPay1();UpdateCost()" <input type="checkbox" name="fifthDecCheckBox" id="fifthDecCheckBox" value="55.00" onclick="DisplayfifthDecPanel();UpdateCost()">
And here is my textbox where the total figure should be displayed:
<input name="text" type="text" id="totalcost" value="">
Thats my attempt on it and I cant get it working. I havn't had much experience with javascript so probably one of the main factors in why
Any help will be appreciated!
Thanks

New Topic/Question
Reply



MultiQuote




|