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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto rate updates

Status
Not open for further replies.

webmast

Programmer
Dec 21, 2001
57
IN
Hi,

I am doing a simple online shopping site project. I have listed out each product like this

Ice cream (250 ml cone) [ ] $1.20
Nuts and Raisens [ ] $0.20
Fruits [ ] $0.50

No.s.(Quantity) [1] Price =

Now this will be the default look, so when a person checks the each checkbox, the price gets automatically added and increasing the number of quantity must increase the price likewisely, etc... How can i get it done dynamically, without refreshing the page each time? (Suppose using layers) Kindly help me out with the solution...

Thanx in advance...

Tommy
 

add this function between the head tags.

Code:
function addUp(x){
var e
var fE = document.forms[x].elements; 
var total = 0
i=1
while (e = fE["food" + i])
{
  if (e.checked)
    total+=Math.abs(fE["food" + i].value)
  i++
}
alert("Total: "+total)
}

and add the form elements

Code:
Ice
<input type="checkbox" name="food1" value="0.50" onClick="addUp(this.form.name)">
<br>
Nuts
<input type="checkbox" name="food2" value="1.20" onClick="addUp(this.form.name)">
<br>
Fruits
<input type="checkbox" name="food3" value="2.50" onClick="addUp(this.form.name)">

HTH

Simon
 
Thanx Simon, its working, but i dont want the result to come on alerts instead on the page itself on the price column.
 
We could approach this 2 ways -

I could write loads of cover-all code to catch each and every possible way you wish to display the information

or

you could post your code and I'll tell you how to do it

what do you think?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top