473,756 Members | 9,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Currency format in textboxes

17 New Member
Am new to javascript.
I need to format the currency in the as numbers are entered in textboxes. I can format the currency in the calculations and display in the totals but can not figure out how to format in input textboxes.


[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javas cript" type="text/javascript">
[/HTML]
Expand|Select|Wrap|Line Numbers
  1. function addthem() {
  2.     //ADD FIRST INPUT VALUE
  3.  
  4.     var add1 = document.addem.input1.value
  5.     var add1 = parseFloat(add1, 10)
  6.     add1 = (isNaN(add1))?0:add1;
  7.  
  8.  
  9.     //ADD SECOND INPUT VALUE
  10.     var add2 = document.addem.input2.value
  11.     var add2 = parseFloat(add2, 10)
  12.     add2 = (isNaN(add2))?0:add2;
  13.  
  14.     //ADD THIRD INPUT VALUE
  15.     var add3 = document.addem.input3.value
  16.     var add3 = parseFloat(add3, 10)
  17.     add3 = (isNaN(add3))?0:add3;
  18.  
  19.     //ADD FOURTH INPUT VALUE
  20.     var add4 = document.addem.input4.value
  21.     var add4 = parseFloat(add4, 10)
  22.     add4 = (isNaN(add4))?0:add4;
  23.  
  24.     //ADD FIFTH INPUT VALUE
  25.     var add5 = document.addem.input5.value
  26.     var add5 = parseFloat(add5, 10)
  27.     add5 = (isNaN(add5))?0:add5;
  28.  
  29.     //ADD SIXTH INPUT VALUE
  30.     var add6 = document.addem.input6.value
  31.     var add6 = parseFloat(add6, 10)
  32.     add6 = (isNaN(add6))?0:add6;
  33.  
  34.  
  35.     //ADD THEM TOGETHER
  36.     return eval(add1) + eval(add2) + eval(add3) + eval(add4) + eval(add5) + eval(add6);
  37.  
  38. }
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. function addthem2() {
  50.     //ADD FIRST INPUT VALUE
  51.     var add7 = document.addem.input7.value
  52.     var add7 = parseFloat(add7, 10)
  53.     add7 = (isNaN(add7))?0:add7;
  54.  
  55.  
  56.     //ADD SECOND INPUT VALUE
  57.     var add8 = document.addem.input8.value
  58.     var add8 = parseFloat(add8, 10)
  59.     add8 = (isNaN(add8))?0:add8;
  60.  
  61.     //ADD THIRD INPUT VALUE
  62.     var add9 = document.addem.input9.value
  63.     var add9 = parseFloat(add9, 10)
  64.     add9 = (isNaN(add9))?0:add9;
  65.  
  66.     //ADD FOURTH INPUT VALUE
  67.     var add10 = document.addem.input10.value
  68.     var add10 = parseFloat(add10, 10)
  69.     add10 = (isNaN(add10))?0:add10;
  70.  
  71.     //ADD THEM TOGETHER
  72.     return eval(add7) + eval(add8) + eval(add9) + eval(add10);
  73.  
  74. }
  75.  
  76. //FUNCTION WILL PARSE THE TOTAL AS DOLLAR FORMAT
  77. function dollarformat(num) {
  78.     num = num.toString().replace(/\$|\,/g,'');
  79.     if(isNaN(num)) num = "0";
  80.         cents = Math.floor((num*100+0.5)%100);
  81.         num = Math.floor((num*100+0.5)/100).toString();
  82.     if(cents < 10) cents = "0" + cents;
  83.         for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  84.             num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
  85.     return ('$' + num + '.' + cents);
  86. }
  87.  
  88. //CALCUATES THE ADD/SUBTRACT VALUES
  89. function calculate() {
  90.     var x = addthem()
  91.    var y = addthem2()            
  92.  
  93.  if(x>y) {
  94.     max = x-y
  95.     document.addem.answer3.value = dollarformat(max)
  96.    }
  97.  
  98.  if(x<y) {
  99.     max = dollarformat(y-x)
  100.     max = "-" + max
  101.     document.addem.answer2.value = max    
  102.    }
  103.  
  104.   if (x==y) {
  105.     max = x-y
  106.     document.addem.answer3.value = dollarformat(max)
  107.    }  
  108. }
  109.  
  110. function addition() {
  111.     document.addem.answer.value = addthem()
  112.     document.addem.answer.value = dollarformat(document.addem.answer.value)
  113.  
  114.     calculate()
  115.  
  116. }
  117.  
  118. function addition2() {
  119.     document.addem.answer2.value = addthem2()
  120.     document.addem.answer2.value = dollarformat(document.addem.answer2.value)
  121.     calculate()
  122. }
  123.  
  124. function subtration() {
  125.    document.addem.answer3.value = subtractthem()
  126.    document.addem.answer3.value = dollarformat(document.addem.answer3.value)
  127.    calculate()
  128. }
  129.  
  130. function calculating() {
  131.    document.addem.answer.value = calculate()
  132.    document.addem.answer.value = dollarformat(document.addem.answer.value)
  133. }
  134.  
[HTML]
</script>
</head>

<body bgcolor="#FFCCC C">
<form name="addem" method="post">
<table border="0" cellpadding="2" cellspacing="0" width="731">
<tr>
<td colspan="3"><h3 align="center" style="margin-top: 0; margin-bottom: 12" ><font face="Verdana" size="3"><b>Tax able Gain Worksheet</b></font></h3>
<tr>
<td width="441" colspan="1">Pol icy #:&nbsp;
<input type="text" name="OBKey__10 1_1" size="30" tabindex="1"></td>
<td width="282" colspan="1" align="right"> Issue Date:&nbsp;
<input type="text" name="OBKey_104 _1" tabindex="4"></td>
</tr>

<tr>
<td width="441" colspan="1" align="left">Po licy Owner:&nbsp;
<input type="text" name="OBKey__10 2_1" size="50" tabindex="2"></td>
<td width="282" colspan="1" align="right">a s of Date:&nbsp;
<input type="text" name="OBKey_103 _1" tabindex="3"></td>
</tr>
</table>

<tr>
<td width="231">&nb sp;</td>
</tr>

<table width="545">
<tr>
<td width="112" align="left"><i nput type="checkbox" name="Full Surrender" value="ON" tabindex="5">
Full Surrender</td>
<td width="95" align="center"> <input type="checkbox" name="Maturity" value="ON" tabindex="6">
Maturity</td>
<td width="127" align="center"> <input type="checkbox" name="Lapse/Expiry" value="ON" tabindex="7">
Lapse/Expiry</td>
<td width="191" align="left"><i nput type="checkbox" name="Overloan" value="ON" tabindex="8">
Overloan</td>
</tr>
</table>

<tr>
<td width="231">&nb sp;</td>
</tr>

<table border="0" cellpadding="2" cellspacing="0" width="741">
<tr>
<td width="400" colspan="1" align="right">B ase Contract Cash Value ............... ............... ............... .......</td>
<td colspan="2" align="left"><i nput type="TEXT" name="input1" onChange="addit ion(addem);" size="20" maxlength="10" tabindex="9" ></td>
</tr>

<tr>
<td colspan="1" align="right">C ash Value of LAD's ............... ............... ............... ............... </td>
<td colspan="2" align="left"><i nput type="TEXT" name="input2" onChange="addit ion(addem);" size="20" maxlength="10" tabindex="10" ></td>
</tr>

<tr>
<td colspan="1" align="right">D ividend Deposit ............... ............... ............... ............... ......</td>
<td colspan="2" align="left"><i nput type="TEXT" name="input3" onChange="addit ion(addem);" size="20" maxlength="10" tabindex="11" ></td>
</tr>

<tr>
<td colspan="1" align="right">P remium Refund ............... ............... ............... ............... .......</td>
<td colspan="2" align="left"><i nput type="TEXT" name="input5" onChange="addit ion(addem)" size="20" maxlength="10" tabindex="12"></td>
</tr>

<tr>
<td colspan="1" align="right">O ther&nbsp;&nbsp ;<input type="text" size="30" >&nbsp;........ ............... .......</td>
<td colspan="2" align="left"><i nput type="TEXT" name="input6" onChange="addit ion(addem)" size="20" maxlength="10" tabindex="13"></td>
</tr>

<tr>
<td colspan="1" align="right">E xchange Fee ............... ............... ............... ............... ...........</td>
<td colspan="2" align="left"><i nput type="TEXT" name="input4" onChange="addit ion(addem)" size="20" maxlength="10" tabindex="14" style= "color:#FF0 000" ></td>
</tr>

<tr>
<td colspan="1" align="right"></td>
<td width="209" colspan="1" align="right">< b>Subtotal</b>
<td width="120" colspan="1" align="right">< input type="TEXT" name="answer" onFocus="this.b lur();" size="20" maxlength="10"> </td>
</tr>

<tr>
<td colspan="1" align="right">C ost Basis (base policy prem. less dividends paid or credited)</td>
<td colspan="2" align="left"><i nput type="TEXT" name="input7" onChange="addit ion2(addem)" size="20" maxlength="10" tabindex="15"></td>
</tr>

<tr>
<td colspan="1" align="right">D ividend Deposit ............... ............... ............... ............... ......</td>
<td colspan="2" align="left"><i nput type="TEXT" name="input8" onChange="addit ion2(addem)" size="20" maxlength="10" tabindex="16"></td>
</tr>

<tr>
<td colspan="1" align="right">O ther&nbsp;&nbsp ;<input type="text" size="30" >&nbsp;........ ............... .......</td>
<td colspan="2" align="left"><i nput type="TEXT" name="input9" onChange="addit ion2(addem)" size="20" maxlength="10" tabindex="17"></td>
</tr>

<tr>
<td colspan="1" align="right">E xchange Fee ............... ............... ............... ............... ...........</td>
<td colspan="2" align="left"><i nput type="TEXT" name="input10" onChange="addit ion2(addem) "size="20" maxlength="10" tabindex="18" style="color:#F F0000 " ></td>
</tr>

<tr>
<td colspan="1" align="right">& nbsp;</td>
<td width="209" colspan="1" align="right">< b>Investment in Contract</b> </td>
<td width="120" colspan="1" align="right">< input type="TEXT" name="answer2" onFocus="this.b lur();" size="20" maxlength="10"> </td>
</tr>

<tr>
<td colspan="1" align="right">& nbsp;</td>
<td width="209" colspan="1" align="right">< b>Amount of Taxable Income</b> </td>
<td width="120" colspan="1" align="right">< input type="TEXT" name="answer3" size="20" maxlength="10" ></td>
</tr>

<tr>
<td width="231">&nb sp;</td>
</tr>

<tr>
<td colspan="1" align="left">10 99 Completed?</td>
<td colspan="1" align="left"><i nput type="checkbox" name="1099Y" value="ON" tabindex="20">Y es&nbsp;&nbsp;
<input type="checkbox" name="1099N" value="ON" tabindex="21">N o</td>
<td width="153" colspan="1" align="right"></td>
</tr>

<tr>
<td colspan="1" align="left">Is Federal withholding notice needed?</td>
<td colspan="1" align="left"><i nput type="checkbox" name="1099Y" value="ON" tabindex="22">Y es&nbsp;&nbsp;
<input type="checkbox" name="1099N" value="ON" tabindex="23">
No&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;Done by</td>
<td colspan="1" align="left"><i nput type="text" name="OBPropert y_UserName" tabindex="24"></td>
</tr>

<tr>
<td colspan="1" align="left">Po ssible state withholding?</td>
<td colspan="1" align="left"><i nput type="checkbox" name="1099Y" value="ON" tabindex="25">Y es&nbsp;&nbsp;
<input type="checkbox" name="1099N" value="ON" tabindex="26">
No&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;D ate</td>
<td colspan="1" align="left"><i nput type="text" name="OBPropert y_DateStored" tabindex="27"></td>
</tr>

<tr>
<td><button type="reset" value="Reset" name="Reset" id="Reset">Rese t</button></td>
<td><button type="submit">S ubmit</button></td>
</tr>
</table>

</form>
<body>
</body>
</html>[/HTML]
Jan 21 '08 #1
16 12088
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN!

Do you want to format on each key press or after the value in a particular text box has changed?
Jan 22 '08 #2
Alexio
17 New Member
Welcome to TSDN!

Do you want to format on each key press or after the value in a particular text box has changed?

After the value in a particular text box has changed. As in formatting after moving to next text box.
Jan 22 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Then apply the currency format function onchange:
Expand|Select|Wrap|Line Numbers
  1. onchange="dollarformat(this.value);"
Jan 22 '08 #4
Alexio
17 New Member
Then apply the currency format function onchange:
Expand|Select|Wrap|Line Numbers
  1. onchange="dollarformat(this.value);"

I currently have an add method being called on change. I tried to add dollarformat(th is.value); to onChange as well but has no effect even when i change it to the only method being called. How do you add more than one method to an event?
Jan 22 '08 #5
Markus
6,050 Recognized Expert Expert
I currently have an add method being called on change. I tried to add dollarformat(th is.value); to onChange as well but has no effect even when i change it to the only method being called. How do you add more than one method to an event?
Expand|Select|Wrap|Line Numbers
  1. <input onchange="someFunction(); someOtherFunction()" />
  2.  
Should work..

Am i right?
Jan 22 '08 #6
Alexio
17 New Member
Expand|Select|Wrap|Line Numbers
  1. <input onchange="someFunction(); someOtherFunction()" />
  2.  
Should work..

Am i right?

It formats into currency but disables my add function.
Jan 22 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
It formats into currency but disables my add function.
Add it first and then apply the currency format.
Jan 23 '08 #8
Alexio
17 New Member
Add it first and then apply the currency format.
Still will not work!
Jan 24 '08 #9
Alexio
17 New Member
Still will not work!
By applying the currency format method before the add method, it disables my add function and vice versa. I can only get one or the other to work. This is totally getting me. Need to get working for project at work. Any help would be mostly appreciated.
Jan 24 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
8866
by: Bill Stanard | last post by:
I have had no success using the format function as follows (the two lines of code run one after the other): 'displays a running total of lblAmtdue.Caption 'contents in txtTotal.Text txtTotal.Text = lblAmtdue.Caption + Val(txtTotal.Text) 'tries to format contents of txtTotal.Text as currency; doesn't work txtTotal.Text = Format$(txtTotal.Text, "Currency")
3
11120
by: John L | last post by:
Well, another basic type of question...amazing how much I've forgotten - never was a VB guru, but. I can see I'll have to pick up a couple VB5 instruction books - any suggestions on a couple good (basic level) learning VB books? Okay - in my database I have a sales total box (textsalestotal) and want to multiply whatever that figure is by .07617 which is Missouri tax - if I just use a click event to multiply, for example $30.34 * .07617...
2
9614
by: Dalan | last post by:
This should not be an issue, but it is. I'm sure that someone knows what little piece of code is needed too persuade Access 97 to include a currency format for labels (Avery, mailing type). Have had no problems with currency formatting on reports - just the labels. Doesn't matter if the associated field in the Table and Form have Format as Currency, because on the labels (for instance $50.00) prints as: 50 The only way to get it to print...
3
3010
by: news.shaw.net | last post by:
I have a subform that contains a currency field. If I tab my way to the field, everything works as desired, a number can be entered, and when I leave the field it is rendered as a currency amount. But if I click on the field with the mouse and enter a number, it shows up like this: 250.00$0.00 with the $0.00 appended to what I type. I have to delete it each time. I've tried a few VBA OnEnter solutions, but nothing has worked so...
2
4558
by: Bob Dydd | last post by:
Hi Everbody Question Changing the regional settings ie. from UK to US AUS etc, Access retains the original currency format that the application was created in. So if an mdb that is written on a computer with Regional Settings Currency Format set to UK £'s , when that mdb is open on a machine
4
22597
by: Gerry Abbott | last post by:
Hi All. How can i put a zero decimal for my currency into my format statement, == & ", for " & & " days. Cost " & Format(,"Currency") which is the data source for a textbox on a report
7
4541
by: zlf | last post by:
1¡¢Here is a number. double nu = 123 2¡¢Format it with 3¡¢The result is "$123" I want to ask how to deformat "$123" to 123 Thx (Currency symbol is not restricted to '$')
2
1585
by: crferguson | last post by:
Hello all! I'm having the oddest issue trying to format a numeric string as currency without decimals. For instance... strSalary = "120000.56" strSalary = Format(strSalary, "$#,##0") 'this one returns "$#,##0" literally, no number strSalary = Format(strSalary, "C0") 'this one returns "C0" literally, no number
2
3883
by: Ian | last post by:
I have an Access 2000 database written in the UK, this database has many fields set to Currency, I now want to move this database over to a user in the USA but my Currency fields still show the UK £ sign. If I look at these currency fields on my UK PC with it set to regional UK (not USA) then the fields format settings just say Currency, if I then add the USA region to my PC and look at the format again it says: £#,##0.00;-£#,##0.00 I...
0
9894
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9679
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7078
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3651
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3141
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2508
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.