djmonkey1
04-27-2006, 04:47 PM
I have the following command (if that's the right term):
var taxTotal = getTaxTotals('tax', taxdescription);
document.getElementById(taxdescription + "-total").value = doFormat(taxTotal, 4);
This is part of a much larger function, where taxdescription is passed as an argument. I'm not going to print up the whole larger function, nor the function getTaxTotals, as I don't think either is pertinent to the issue I'm facing.
The problem is that the id (taxdescription + "-total") doesn't necessarily exist(it might, it might not, but the fields that would be summed to calculate it always do), so when the JavaScript tries to perform document.getElementById(taxdescription + "-total").value = doFormat(taxTotal, 4); it throws up an error that document.getElementById(taxdescription + "-total") has no properties This is ok, sort of, since all the other calculations are done properly and if that field doesn't exist we don't need to have it totalled up anyway.
Basically what I'm asking is how do I re-write document.getElementById(taxdescription + "-total").value = doFormat(taxTotal, 4); so that the JavaScript won't give the error when the element doesn't exist? For instance could you write something like ifExists (getElementById(taxdescription + "-total")) { then enter document.getElementById(taxdescription + "-total").value = doFormat(taxTotal, 4);
}?
var taxTotal = getTaxTotals('tax', taxdescription);
document.getElementById(taxdescription + "-total").value = doFormat(taxTotal, 4);
This is part of a much larger function, where taxdescription is passed as an argument. I'm not going to print up the whole larger function, nor the function getTaxTotals, as I don't think either is pertinent to the issue I'm facing.
The problem is that the id (taxdescription + "-total") doesn't necessarily exist(it might, it might not, but the fields that would be summed to calculate it always do), so when the JavaScript tries to perform document.getElementById(taxdescription + "-total").value = doFormat(taxTotal, 4); it throws up an error that document.getElementById(taxdescription + "-total") has no properties This is ok, sort of, since all the other calculations are done properly and if that field doesn't exist we don't need to have it totalled up anyway.
Basically what I'm asking is how do I re-write document.getElementById(taxdescription + "-total").value = doFormat(taxTotal, 4); so that the JavaScript won't give the error when the element doesn't exist? For instance could you write something like ifExists (getElementById(taxdescription + "-total")) { then enter document.getElementById(taxdescription + "-total").value = doFormat(taxTotal, 4);
}?