View Full Version : Help with assigning values to form options?

02-24-2007, 06:21 PM

Let me try to do my best to explain this...
I have a business website that specializes in building custom computers. Customers can use our online form to select components for their computer from various categories (Hard drive size, processor, memory, ect..)

Take a look at the page here: www.plugcomputers.com/amdschedule.php

As you can see there are many radio buttons with different computer part choices. I wanted to add some way to assign a dollar value to each different part, so the customer knows how much its costing them with each upgrade. If you scroll to the bottom of the page you will see some red text, I want that price to reflect the sum off all the choices they made above. Adding up all the different upgrade dollar amounts so that they have an idea how much their computer will be while selecting components.

The current red number at the bottom is the base price with all the default selected values.

For example, in the first category "Processor"
The base price includes the AMD x2 3800+, If i wanted the upgrade price for the next option (the AMD x2 4400+) to be +$50 how can I get that into the form so when the user clicks that radio the price at the bottom automatically adds $50?

Thank you and I appreciate any help...

02-25-2007, 06:21 AM
didnt you post this exact question a few months back?

02-25-2007, 10:33 PM
I did, but the response I got never worked out. I was hoping maybe there were some new people on here that could help me get this figured out. I appreciate any help...

02-25-2007, 10:58 PM
you could assign a "fake" attribute to each radio button.

<input type="radio" name="cputype" value="amd" priceattribute="$165.99"/>

and then with javascript i believe you can use getAttribute to get the value of that.


its a bit of a work-around, but its a nice easy way to associate information like this with a specific form item.

hope that helps.

02-27-2007, 02:24 AM
I can't really figure that out JayStang...can you be a bit more descriptive? How can i get that to total at the bottom of the page?

02-27-2007, 03:45 AM
This is probably not the right way to do it, but it works:

Add to each product div an id and a value like this:
<div class="item" id="item0" value="100.00">

insert: onclick="calc(0,120.20)" for each input option.

First number is the product group and the second is the price.

A onLoad call the calc(x,xx.xx) would be good to show initial total.

function calc(id,amount){
document.getElementById('item'+id).value= amount
var total = 0
for (var i=0; i<17; i++){ // you have 17 product groups
total += parseFloat(document.getElementById('item'+i).value)
document.getElementById('total').innerHTML = total

replace your red total text with this.
<span id="total"></span>