Hi,
This should be simple, but I can’t figure it out.
I have the below external js file:
var Cost, GST, Grand_Total;
function tally()
{
Cost = 0;
if (document.form_1.element_19_7.checked) { Cost = Cost + 179; }
if (document.form_1.element_19_6.checked) { Cost = Cost + 149; }
if (document.form_1.element_19_5.checked) { Cost = Cost + 79; }
if (document.form_1.element_19_4.checked) { Cost = Cost + 49; }
if (document.form_1.element_19_2.checked) { Cost = Cost + 19; }
if (document.form_1.element_20_7.checked) { Cost = Cost + 179; }
if (document.form_1.element_20_6.checked) { Cost = Cost + 149; }
if (document.form_1.element_20_5.checked) { Cost = Cost + 79; }
if (document.form_1.element_20_4.checked) { Cost = Cost + 49; }
if (document.form_1.element_20_2.checked) { Cost = Cost + 19; }
if (document.form_1.element_21_7.checked) { Cost = Cost + 179; }
if (document.form_1.element_21_6.checked) { Cost = Cost + 149; }
if (document.form_1.element_21_5.checked) { Cost = Cost + 79; }
if (document.form_1.element_21_4.checked) { Cost = Cost + 49; }
if (document.form_1.element_21_2.checked) { Cost = Cost + 19; }
if (document.form_1.element_22_7.checked) { Cost = Cost + 179; }
if (document.form_1.element_22_6.checked) { Cost = Cost + 149; }
if (document.form_1.element_22_5.checked) { Cost = Cost + 79; }
if (document.form_1.element_22_4.checked) { Cost = Cost + 49; }
if (document.form_1.element_22_2.checked) { Cost = Cost + 19; }
if (document.form_1.element_23_7.checked) { Cost = Cost + 179; }
if (document.form_1.element_23_6.checked) { Cost = Cost + 149; }
if (document.form_1.element_23_5.checked) { Cost = Cost + 79; }
if (document.form_1.element_23_4.checked) { Cost = Cost + 49; }
if (document.form_1.element_23_2.checked) { Cost = Cost + 19; }
if (document.form_1.element_24_7.checked) { Cost = Cost + 179; }
if (document.form_1.element_24_6.checked) { Cost = Cost + 149; }
if (document.form_1.element_24_5.checked) { Cost = Cost + 79; }
if (document.form_1.element_24_4.checked) { Cost = Cost + 49; }
if (document.form_1.element_24_2.checked) { Cost = Cost + 19; }
if (document.form_1.element_25_7.checked) { Cost = Cost + 179; }
if (document.form_1.element_25_6.checked) { Cost = Cost + 149; }
if (document.form_1.element_25_5.checked) { Cost = Cost + 79; }
if (document.form_1.element_25_4.checked) { Cost = Cost + 49; }
if (document.form_1.element_25_2.checked) { Cost = Cost + 19; }
GST = (Cost * 0.13);
Cost = dollar(Cost);
GST = dollar(GST);
Grand_Total = parseFloat(Cost) + parseFloat(GST);
Grand_Total = dollar(Grand_Total);
document.form_1.element_59.value = "$" + Cost;
document.form_1.element_61.value = "$" + GST;
document.form_1.element_60.value = "$" + Grand_Total;
}
function dollar (amount)
{
amount = parseInt(amount * 100);
amount = parseFloat(amount/100);
if (((amount) == Math.floor(amount)) && ((amount - Math.floor (amount)) == 0))
{
amount = amount + ".00"
return amount;
}
if ( ((amount * 10) - Math.floor(amount * 10)) == 0)
{
amount = amount + "0";
return amount;
}
if ( ((amount * 100) - Math.floor(amount * 100)) == 0)
{
amount = amount;
return amount;
}
return amount;
}
I need to add an onclick handler to the checkbox fields:
onclick="tally()
The form is being created dynamically through a database, so I can’t add the onclick event to the fields themselves.
How would I add the onclick function to the script instead?
I’m just not code saavy enough to figure it out.
Any help would be greatly appreciated.
Cheers & thanks in advance