merlingoth
09-21-2011, 11:31 PM
I'm new to javascript but not to programming. Here is my code:
PHP Code:
print "<form name='goldcalculator'>";
print "<input type='hidden' name='goldspot' value='$goldvalue'>";
print "<select name='gunit' onchange='updateTotal();'>";
print "<option value='20'>Pennyweight (DWT)</option>";
print "<option value='31.1'>Grams (g)</option>";
print "</select><br>";
print "10K <input type='text' name='10k' onchange='updateTotal();'><br>";
print "14K <input type='text' name='14k' onchange='updateTotal();'><br>";
print "18K <input type='text' name='18k' onchange='updateTotal();'><br>";
print "22K <input type='text' name='22k' onchange='updateTotal();'><br>";
print "24K <input type='text' name='24k' onchange='updateTotal();'><br>";
print "TOTAL <input type='text' name='totalprice'>";
print "</form>";
<script language="JavaScript">
function updateTotal()
{
var u = document.goldcalculator.gunit.value;
var spotprice = document.goldcalculator.goldspot.value / u;
var gold10 = document.goldcalculator.10k.value;
var gold14 = document.goldcalculator.14k.value;
var gold18 = document.goldcalculator.18k.value;
var gold22 = document.goldcalculator.22k.value;
var gold24 = document.goldcalculator.24k.value;
var calculatedPrice = document.goldcalculator.totalprice.value;
calculatedPrice = ((spotprice*.999*gold24)+(spotprice*.916*gold22)+(spotprice*.75*gold18)+(spotprice*.585*gold14)+(spo tprice*.417*gold10));
}
</script>
I don't know where to begin to debug this. It's very simple. The $goldvalue variable is non-editable and is pulled off my MySQL database and that works. They fill in the inputs via the PHP form and then it basically adds them up and spits out the total. Can someone tell me what's wrong?
PHP Code:
print "<form name='goldcalculator'>";
print "<input type='hidden' name='goldspot' value='$goldvalue'>";
print "<select name='gunit' onchange='updateTotal();'>";
print "<option value='20'>Pennyweight (DWT)</option>";
print "<option value='31.1'>Grams (g)</option>";
print "</select><br>";
print "10K <input type='text' name='10k' onchange='updateTotal();'><br>";
print "14K <input type='text' name='14k' onchange='updateTotal();'><br>";
print "18K <input type='text' name='18k' onchange='updateTotal();'><br>";
print "22K <input type='text' name='22k' onchange='updateTotal();'><br>";
print "24K <input type='text' name='24k' onchange='updateTotal();'><br>";
print "TOTAL <input type='text' name='totalprice'>";
print "</form>";
<script language="JavaScript">
function updateTotal()
{
var u = document.goldcalculator.gunit.value;
var spotprice = document.goldcalculator.goldspot.value / u;
var gold10 = document.goldcalculator.10k.value;
var gold14 = document.goldcalculator.14k.value;
var gold18 = document.goldcalculator.18k.value;
var gold22 = document.goldcalculator.22k.value;
var gold24 = document.goldcalculator.24k.value;
var calculatedPrice = document.goldcalculator.totalprice.value;
calculatedPrice = ((spotprice*.999*gold24)+(spotprice*.916*gold22)+(spotprice*.75*gold18)+(spotprice*.585*gold14)+(spo tprice*.417*gold10));
}
</script>
I don't know where to begin to debug this. It's very simple. The $goldvalue variable is non-editable and is pulled off my MySQL database and that works. They fill in the inputs via the PHP form and then it basically adds them up and spits out the total. Can someone tell me what's wrong?