Log in

View Full Version : 3 item calculator



RedBullAddict
03-15-2007, 05:49 PM
I am trying to figure out a way to build a 3 item calculator. The way I see this set up is as follows:

Checkbox1 Checkbox2 Checkbox3

Total Displayed Here


I am trying to make something so when a check box is selected the price will display in an input box. If 2 items are selected, it will display the combined price and if 3 are selected it will do the same.

I know very little php, but was told it could be done.

Any help or ideas would be great!

Here is a link to a quick html page I put together.

http://www.settlementonehosting.com/Clients/jason/calculator.html

Thanks again!!

nikomou
03-16-2007, 10:23 PM
hey..

its difinatly possable.. but i think javascript would be a better option for u.. or a combination of both php and js..

djr33
03-16-2007, 11:44 PM
PHP would require the page to be reloaded or the form sent. With javascript, it could respond immediately to the checkboxes.

for each checkbox... here's something you could try...

<input type="checkbox" value="3.88" onChange="if (this.checked == 1) { pricefield.value = pricefield.value+this.value; } else { pricefield.value = pricefield.value-this.value; }">

I believe that would suit your needs.

This would, by the way, require that the "results" field be called:
<input type="text" id="pricefield" name="pricefield">

Also, to avoid weird errors, it would require that each checkbox load unchecked, and the value of the pricefield start at 0.