Forums
This topic is locked
PHP and JavaScript
Posted 17 May 2008 23:44:06
1
has voted
17 May 2008 23:44:06 Alan Torres posted:
I'm using a javascript function that adds two values. For example:I have an SQL table that has these columns:
id, description, price
They are displayed and repeated for every available record. The values from the "price" column are set in a checkbox.
So when the user clicks the checkbox, it should call the function that will add the value to another textfield value. If the user unchecks the box, it should subtract it. However, i am not able to get the javascript to work when the record is repeated.
Any and all input is greatly appreciated. Thank you.
Below is the code i'm using for adding and subtracting the values:
<pre id=code><font face=courier size=2 id=code> <script language="javascript" type="text/javascript">
function doMath(){
if (accessories.interior.checked==true) {
var a = accessories.interior.value;
var b = accessories.total_retail.value;
var c = accessories.total_subaru.value;
var total1 = parseInt(a) + parseInt(b);
var total2 = parseInt(a) + parseInt(c);
accessories.total_subaru.value = total2.toFixed(2);
accessories.total_retail.value = total1.toFixed(2);
} else if (accessories.interior.checked==false){
var a = accessories.interior.value;
var b = accessories.total_retail.value;
var c = accessories.total_subaru.value;
var total1 = parseInt(b) - parseInt(a);
var total2 = parseInt(c) - parseInt(a);
accessories.total_subaru.value = total2.toFixed(2);
accessories.total_retail.value = total1.toFixed(2);
}
}
</script></font id=code></pre id=code>