Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 14th, 2009, 03:21 PM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Question 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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set a value in datagrid to currency format? jhansib4u ADO.NET 0 December 12th, 2007 01:43 AM
Currency Format kdkcchoco ASP.NET 1.0 and 1.1 Professional 1 March 29th, 2007 08:13 AM
Currency Format heerajee Pro PHP 2 June 5th, 2006 02:24 AM
format currency civa Access 3 December 16th, 2005 03:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.