Log in

View Full Version : Drop-Down Box price addition help



viper102464
06-02-2006, 04:57 AM
Hello all,

Im new to these forums and new to javascript. I was wondering if anybody would be able to help me with the script that i am using. I am making a website that people would be able to go to, to build a computer and to have a thing that automatically updates the price as they choose the items. Similar to Dell's setup on their site, but simpler, with drop-down menues.

Example:
http://configure.us.dell.com/dellstore/config.aspx?c=us&cs=19&l=en&oc=DXPS600F4&s=dhs

Here is the site that i want the script to work on, im still working on it, but it should give you enough information to let me know what i need to do to make it work with drop down boxes.

http://www.oharanetworks.com/jcr/build/test.htm

If anyone could give me any help, that would be great. Thanks.:)

benslayton
06-02-2006, 05:29 AM
it would be cool if you could use this in it.
http://www.dynamicdrive.com/dynamicindex1/combodescribe.htm:) :D ;)

viper102464
06-02-2006, 05:50 AM
Yes, that would be cool too, I think i will use that script, thanks. But i still need help getting the calculate price thing working, as posted above.

Help Please

Thanks

jscheuer1
06-02-2006, 05:56 AM
<select size="1" name="D1" onchange="this.form.price1.value=this.options[this.selectedIndex].value;calculate()">
<option selected>Select Processor</option>
<option value="639.00">AMD Athlon 64 FX55 San Diego 2000MHz HT Socket 939 [Subtract $172]
</option>
<option value="811.00">AMD Athlon 64 FX60 Toledo 2000MHz HT Socket 939 Dual Core [Add $42]
</option>
<option value="853.00">AMD Athlon 64 FX57 San Diego 2000MHz HT Socket 939 [Included in Price]
</option>
</select>

viper102464
06-02-2006, 06:10 AM
SWEET! It works, thank you so much!
But how could i make it so that when, for example the option with the "[Included in Price]" is initially selected and it initially has the total in the box?

Any help would be wonderful.

Thanks again

jscheuer1
06-02-2006, 06:47 AM
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#000000" onload="calculate();">

<script type="text/javascript">
function cent(amount) {
return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

function calculate() {
var p1, p2, p3;
p1 = test.price1.value * 1;
p2 = test.price2.value * 1;
p3 = test.price3.value * 1;
total_price = p1 + p2 + p3;
test.total_price.value = cent(Math.round(total_price*Math.pow(10,2))/Math.pow(10,2));
}

</script>

<form name="test" method="post" action="">
<input type="hidden" value="853.00" name="price1">
<input type="hidden" value="202.00" name="price2">
<input type="hidden" value="1000.00" name="price3">

<p><font face="Arial" size="2" color="#FFFFFF">Total: </font>

<input type="text" name="total_price" font="arial" size="10" readonly></p>

<p>&nbsp;</p>
<p><font color="#FFFFFF" face="Arial">Here is what I want to work:</font></p>
<p>
<b><font face="Arial" size="2" color="#FFFFFF">Processors</font></b></p>

<p><select size="1" name="D1" onchange="this.form.price1.value=this.options[this.selectedIndex].value;calculate()">
<option value="639.00">AMD Athlon 64 FX55 San Diego 2000MHz HT Socket 939 [Subtract $172]
</option>
<option value="853.00">AMD Athlon 64 FX60 Toledo 2000MHz HT Socket 939 Dual Core [Add $42]
</option>
<option value="811.00" selected>AMD Athlon 64 FX57 San Diego 2000MHz HT Socket 939 [Included in Price]
</option>
</select></p>
<p>
<b><font face="Arial" size="2" color="#FFFFFF">Memory</font></b></p>

<p><select size="1" name="D2" onchange="this.form.price2.value=this.options[this.selectedIndex].value;calculate()">
<option value="202.00" selected>CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM DDR 400 (PC 3200) Unbuffered Dual Channel w/ Platinum Heat Spreader [Included in Price]
</option>
<option value="464.00">CORSAIR XMS 4GB (4 x 1GB) 184-Pin DDR SDRAM DDR 400 (PC 3200) Unbuffered Dual Channel w/Activity LED's [Add $262]
</option>
<option value="404.00">CORSAIR XMS 4GB (4 x 1GB) 184-Pin DDR SDRAM DDR 400 (PC 3200) Unbuffered Dual Channel w/ Platinum Heat Spreader [Add $202]
</option>
<option value="232.00">CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM DDR 400 (PC 3200) Unbuffered Dual Channel w/Activity LED's [Add $30]
</option>
</select></p>
<p>
<b><font face="Arial" size="2" color="#FFFFFF">Video Cards</font></b></p>
<p><select size="1" name="D3" onchange="this.form.price3.value=this.options[this.selectedIndex].value;calculate()">
<option value="590.00">Dual XFX GeForce 7900 GT EXTREME (520MHz Core Clock) 256MB GDDR3 PCI Express x16 [Subtract $410]
</option>
<option value="1000.00" selected>Dual BFG Tech Geforce 7900GTX (670MHz Core Clock)512MB GDDR3 PCI Express x16 [Included In Price]

</option>
</select></p>
</form>

</body>
</html>

viper102464
06-02-2006, 06:52 AM
Awesome! Thanks for all your help!:) :) :)