Format input as Currency and Multiply
I have a javascript that multiplies two intergers, without the currency formatting including the commas. The users would now like to have commas with the data entry and result; but the script (provided by another developer) gives and NaN error when I use commas.
I like this because it does not require a submit button to yield the desired results.
How can I have currency formatting and the multiplication without it hiccupping?
Thank you.
Gail
My code
(A)
<scriptlanguage="javascript"type="text/javascript">
function Calculate() {
var value1 = document.getElementById('<%=txtQuantity.ClientID%>').value;
var value2 = document.getElementById('<%=txtUnitPrice.ClientID%>').value;
var result = value1 * value2;
document.getElementById('<%=txtResults.ClientID%>').value = result;
}
</script>
and
(B)
<scriptlanguage="javascript"type="text/javascript">
function CalculateBudget() {
var value1 = parseFloat(document.getElementById('<%=dvBudgetRequestUpdate.FindControl("txtQuantity ").ClientID%>').value);
var value2 = parseFloat(document.getElementById('<%=dvBudgetRequestUpdate.FindControl("txtUnitPric e").ClientID%>').value);
var result = value1 * value2;
document.getElementById('<%=dvBudgetRequestUpdate.FindControl("txtTotalEst Cost").ClientID%>').value = result;
}
</script>
Both (A) and (B) are needed on differenc pages.
Again, thank you.
|