Jump to content

Auto Sum Order Form total.


samf_20

Recommended Posts

Hi,

 

Im currently creating a Order form and everything works fine except the Order total I got. Currently it does work but not properly and I cannot figure out how to fix the issue.

 

Basically I got 4 checkboxes with 4 seperate values. For example I would select one checkbox and the order total box will display £55. Then I would de-select it and it would display £0. But, if i select another box whilst another checkbox is selected it will add the new checkboxes values onto the previous value where is shouldnt write on top it should overwrite it. I got some java script so my fourth checkbox can be selected with any of the other 3 but only one of the other 3 can be selected at a time.

 

The javascript is:

function UpdateCost(ev) {
    var sum = Number(document.getElementById('totalcost').value);
    if (ev.checked){
        sum += Number(ev.value);
	document.getElementById('totalcost').value = sum.toFixed(2);
    }
    else{
        sum -= Number(ev.value);
    }
    document.getElementById('totalcost').value = sum.toFixed(2);
}

 

My HTML is:

 

<input name="registrationday1" type="checkbox" id="registrationday1" value="55.00" onClick="CheckRegistrationDaysBothOption();DisplayconfPay1();UpdateCost(this);"> 

                            <input type="checkbox" name="registrationday2" id="registrationday2" value="55.00" onClick="CheckRegistrationDaysBothOption();DisplayconfPay2();UpdateCost(this);">

<input name="registrationday3" type="checkbox" id="registrationday3" value="100.00" onClick="CheckRegistration56Days();DisplayconfPay3();UpdateCost(this);">

                          <input type="checkbox" name="fifthDecCheckBox" id="fifthDecCheckBox" value="55.00" onClick="DisplayfifthDecPanel();UpdateCost(this);">

 

Also this is the javascript I use to un-check my checkboxes:

 

		function CheckRegistration56Days()
	{
		var day1 = document.getElementById('registrationday1');
		var day2 = document.getElementById('registrationday2');
		var day3 = document.getElementById('registrationday3');

		if(day3.checked)
		{
			day2.checked = false;
			day1.checked = false;
		}
		else if(!day3.checked)
		{
			day2.checked = false;
			day1.checked = false;
		}
	}

	function CheckRegistrationDaysBothOption()
	{
		var day1 = document.getElementById('registrationday1');
		var day2 = document.getElementById('registrationday2');
		var day3 = document.getElementById('registrationday3');

		if(day2.checked)
		{
			day1.checked = false;
			day3.checked = false;
		}
		else if(!day2.checked)
		{
			day3.checked = false;
		}
	}

 

Thanks, any help will be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/134500-auto-sum-order-form-total/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.