...

View Full Version : HELP how to show the difference in a form



theatreus
11-11-2010, 10:11 PM
is there a simple way or any way at all of making the ($50.00) ($40.00) ($30.00) ($20.00) show the difference instead... like if i chose $40.00 then the $50.00 would say +$10.00 and the 30 and 20 would say -$10.00 and -$20.00

<p align="left">CASE</p>
<center>
<select name="caseselect" style="width:625px" onchange="Calculate(); swapImage(this,'caseimg');">
<option value="50#COOLER MASTER Elite 310red.jpg" selected="1">COOLER MASTER Elite 310 Red ($50.00)</option>
<option value="40#COOLER MASTER Elite 310blue.jpg">COOLER MASTER Elite 310 Blue ($40.00)</option>
<option value="30#COOLER MASTER Elite 310orange.jpg">COOLER MASTER Elite 310 Orange ($30.00)</option>
<option value="20#COOLER MASTER Elite 310silver.jpg">COOLER MASTER Elite 310 Silver ($20.00)</option>
</select>

theatreus
11-11-2010, 10:12 PM
if not... thats fine you guys have helped me enough i guess... but i really do believe im getting close to the end of this all

Old Pedant
11-11-2010, 11:04 PM
<html>
<head>
<script>
function Calculate() { };
function swapImage() { };

function fixAmounts(sel)
{
var curopt = sel.options[sel.selectedIndex]; // chosen option
var curamt = parseFloat( curopt.value.split("#")[0] ); // price of that option
for ( var op = 0; op < sel.options.length; ++op )
{
var option = sel.options[op];
var oamt = parseFloat( option.value.split("#")[0] );
var diff = oamt - curamt;
var sign = ( diff > 0 ) ? "+" : (diff < 0 ) ? "-" : "";
if ( diff == 0 ) diff = curamt; // chosen option gets actual price??
option.text = option.text.substring( 0, option.text.indexOf("(") )
+ "(" + sign + "$" + Math.abs(diff).toFixed(2) + ")";
}
}
</script>
</head>
<body>
<form>
<select name="caseselect" style="width:625px" onchange="fixAmounts(this); Calculate(); swapImage(this,'caseimg');">
<option value="50#COOLER MASTER Elite 310red.jpg" selected="1">COOLER MASTER Elite 310 Red ($50.00)</option>
<option value="40#COOLER MASTER Elite 310blue.jpg">COOLER MASTER Elite 310 Blue (-$10.00)</option>
<option value="30#COOLER MASTER Elite 310orange.jpg">COOLER MASTER Elite 310 Orange (-$20.00)</option>
<option value="20#COOLER MASTER Elite 310silver.jpg">COOLER MASTER Elite 310 Silver (-$30.00)</option>
</select>
</form>
</body>

If you opt to omit the line in red, then change the amount in magenta to $0.00, of course.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum