ecnarongi
12-10-2008, 06:44 PM
I have a function:
function updateTotal(arg) {
var curr_total, new_total;
curr_total = parseFloat(document.getElementById('subtotal').value);
new_total = curr_total + parseFloat(arg);
document.getElementById('subtotal').value = new_total;
document.getElementById('services_subtotal').innerHTML = new_total;
}
this works fine the first time it is executed, but if it is executed any time after that I receive a "document.getElementById('subtotal') is null" error. I just would like know if anyone can see a possible issue with the above function that I am missing, and explain why the code works the first time but not the second or thereafter.
*note: subtotal is a hidden form element and it has a default value of 0.
edit: forgive me, I didn't give enough information. I put the form element subtotal inside the div that I rewrote with innerHTML and that caused the entire problem.
function updateTotal(arg) {
var curr_total, new_total;
curr_total = parseFloat(document.getElementById('subtotal').value);
new_total = curr_total + parseFloat(arg);
document.getElementById('subtotal').value = new_total;
document.getElementById('services_subtotal').innerHTML = new_total;
}
this works fine the first time it is executed, but if it is executed any time after that I receive a "document.getElementById('subtotal') is null" error. I just would like know if anyone can see a possible issue with the above function that I am missing, and explain why the code works the first time but not the second or thereafter.
*note: subtotal is a hidden form element and it has a default value of 0.
edit: forgive me, I didn't give enough information. I put the form element subtotal inside the div that I rewrote with innerHTML and that caused the entire problem.