ok, I have an order form comprising <select> boxes, populated using PHP from an SQL database...I want to use Javascript to print and refresh the total in an input box at the bottom every time a drop down box is changed...
I have this code, which doesn't work...not surpsising really...any ideas why not, or how to do this?
<script language="JavaScript">
function calc(obj)
{
var price=300.00;
for (var item=0; item < obj.elements.length; item++)
{
for (var sel=0; sel < obj.elements[item].length; sel++)
{
price = price+(eval(obj.elements[item].options[sel].value.substring((obj.elements[item].options[sel].value.length-7),
(obj.elements[item].options[sel].value.length)))); }
}
var cost = round2(price);
document.sys.tot.value= "Total Price £"+cost+" Inc.VAT";
window.status = "Total Price £"+cost+" Inc.VAT";
}
function round2(amount)
{
amount = Math.round(100*amount);
var amountstr = "" + amount;
amountstr = amountstr.substring(0,(amountstr.length-2)) + "." + amountstr.substring((amountstr.length-2),
amountstr.length);
return amountstr
}
</script>
The <select> boxes are in this format:
<select name="CPUType" id="CPUType" style="width:360px" OnChange="calc(this.form)">
<?php
$result = mysql_query("SELECT prodname, sellprice FROM Products WHERE cat='CPUType' ORDER BY ourcost", $db);
while ($ra = mysql_fetch_array($result))
{
$name=$ra["prodname"];
$price=$ra["sellprice"];
echo" <option value=”$price”>$name [£$price]</option>";
}
?>
</select>
HELP...!