Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating Sums - direction needed

Status
Not open for further replies.

hpadwal

Programmer
Feb 6, 2006
57
GB
Hello all,

I need some pointers on how to approach this task, had a look on google but not finding what i need.

I need the summary section of my page to update everytime a user clicks a checkbox of a package they want to buy (let say they are £10 each)

The output value should also go into a hidden field so i can add it to the database.

Can you help?

Will have some code posted soon, just hopeing this way would be more clear.



_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

- Doh

 
You'll have to convert the contents of the hidden input field from a string into a number (using the parseInt() function) when you go to add the new value to it (since + acts as a concatenator when working with strings).

I would write a single function to set the value of the hidden field and update the contents of the summary section (using innerHTML to update the contents of a container with an ID).

Once you have some code up... and some specific issues... I'll chime back in if I can.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Hello all, i have created the following script to answer my own question.

its very LONG and im sure there is an easir way to do this, but here it is.

ps. if you know how i can improve the script let me know. Thanks

Code:
function calculate(thisform)
{
	packs = 0;
	prempack = 0;
	
 	if (thisform.package1.checked)	
   	{
		packs = packs + 1
  	}
  	if (thisform.package2.checked)	
   	{
		packs = packs + 1
  	}
  	if (thisform.package3.checked)	
   	{
		packs = packs + 1
  	}
  	if (thisform.package4.checked)	
   	{
		packs = packs + 1
  	}
  	if (thisform.package5.checked)	
   	{
		packs = packs + 1
  	}
  	if (thisform.package6.checked)	
   	{
		packs = packs + 1
  	}
  	
  	if (packs == 0) 
	{
		packsum = 0.00;
		totalpacksum = 0.00;
	}
  	
  	if (packs == 2) 
	{
		packsum = 10.25;
		totalpacksum = 21.50;
	}
	if (packs == 4) 
	{
		packsum = 13.00;
		totalpacksum = 26.00;
	}
	if (packs == 5) 
	{
		packsum = 15.25;
		totalpacksum = 30.50;
	}
	thisform.packoutput.value = packsum;
	
	if (thisform.prempack1.checked)	
   	{
		prempack = prempack + 1
  	}
  	if (thisform.prempack2.checked)	
   	{
		prempack = prempack + 1
  	}
  	if (thisform.prempack3.checked)	
   	{
		prempack = prempack + 1
  	}
  	if (thisform.prempack4.checked)	
   	{
		prempack = prempack + 1
  	}
	if (prempack == 0) 
	{
		premsum = 0.00;
	}
	if (prempack == 1) 
	{
		premsum = 5.00;
	}
	if (prempack == 2) 
	{
		premsum = 10.00;
	}
	if (prempack == 3) 
	{
		premsum = 15.00;
	}
	if (prempack == 4) 
	{
		premsum = 20.00;
	}
	thisform.premoutput.value = premsum;
	thisform.totaloutput.value = premsum + packsum;
	thisform.discountsum.value = premsum + totalpacksum;
	
}

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

- Doh

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top