473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem(s) on number auto-format function.

Thanks in advance to everyone that will give me help for these questions.

The function formatCurrency is used to auto-format a numeric value with thousands
separators and a decimal separator.

It works, but still has the following problems:

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°°°°°°°°°°°°°

Problem 1.

The function automatically inserts the decimal separator

onKeyPress="return(currencyFormat(this,',','.',eve nt))" //(where '.' is the decsep)

This is a problem because when a user tries to write 1000 (one thousand) it is formatted
as 10.00.

I need to modify the function so that it inserts the digit decSep only when the user
digits the decSep key.

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°°°°°°°°°°°°°°

Problem 2.

As it is the function only supports numbers with two decimals, but it would be useful to
pass the decimal position as an argument of the function itself.

I tried to add the argument decSepPos (decimal separator position)
and modify the function in these way:

------------

Line 7:

function currencyFormat(fld, milSep, decSep, e) {

Becomes

function currencyFormat(fld, milSep, decSep, decSepPos, e) {
-----------
line 44:

fld.value += decSep + aux.substr(len - 2, len);

becomes

fld.value += decSep + aux.substr(len - decSepPos, len);

--------------
line 59:

onKeyPress="return(currencyFormat(this,',','.',eve nt))">

becomes

onKeyPress="return(currencyFormat(this,',','.','3' ,event))">

where '3' is clearly an example.
-------------------------------------------------

This modification works well, but only when decSepPos is >=2.
If the passed value is 1 or 0 the function stops working well.

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°°°°°°°°°

Problem 3.

In firefox the TAB key does not work (while it works in ie).
This implies not to be able to switch from a textbox to another object using the tab key.I
tried to add line 16 the following line:

if (whichCode == 9) return true; // (9 is the keycode of TAB key)

Without obtaining any result.

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°°°°
Here is the sample page I'im working on
Thanks to everybody will support me on one or more of these problems.

Paolo

§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
<HTML>

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

function currencyFormat(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true; // Enter
if (whichCode == 8) return true; // Delete
key = String.fromCharCode(whichCode); // take the key from keycode
if (strCheck.indexOf(key) == -1) return false; // Unvalid key
len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
//if (len == 1) fld.value = '0'+ decSep + '0' + aux;
//if (len == 2) fld.value = '0'+ decSep + aux;
if (len 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}

</script>

</HEAD>

<BODY>

<form>
Input value:
<input type="text" name="test" length="15"
onKeyPress="return(currencyFormat(this,',','.',eve nt))">
</form>
</BODY>
</HTML>
Oct 16 '08 #1
2 2623
In comp.lang.javascript message <48**********************@reader1.news.t
in.it>, Thu, 16 Oct 2008 18:10:15, paolo <pa********@digitalminds.it>
posted:
>Thanks in advance to everyone that will give me help for these questions.
Non si dovrebbe provare a formattare un campo di inserimento dati mentre
viene riempito dall'utente.

Leggi le FAQ di newsgroup, regolarmente pubblicato qui e / via / un link
qui sotto, in particolare la sezione "How do I convert a Number into a
String with exactly 2 decimal places?" ("Come faccio a convertire un
numero in una stringa con esattamente 2 decimali?") e il suo
collegamento al <http://www.merlyn.demon.co.uk/js-round.htm>.

È una buona idea leggere il newsgroup c.l.j ed il relativo FAQ. Veda sotto.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 16 '08 #2
On Thu, 16 Oct 2008 20:35:22 +0100, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:
>In comp.lang.javascript message <48**********************@reader1.news.t
in.it>, Thu, 16 Oct 2008 18:10:15, paolo <pa********@digitalminds.it>
posted:
>>Thanks in advance to everyone that will give me help for these questions.

Non si dovrebbe provare a formattare un campo di inserimento dati mentre
viene riempito dall'utente.

Leggi le FAQ di newsgroup, regolarmente pubblicato qui e / via / un link
qui sotto, in particolare la sezione "How do I convert a Number into a
String with exactly 2 decimal places?" ("Come faccio a convertire un
numero in una stringa con esattamente 2 decimali?") e il suo
collegamento al <http://www.merlyn.demon.co.uk/js-round.htm>.

È una buona idea leggere il newsgroup c.l.j ed il relativo FAQ. Veda sotto.
come vedi Paolo, anche qui la risposta è sempre la stessa... :-)

Oct 17 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dave | last post by:
I have one auto number field in one table in sql server 2000. I'm inserting new record using insert statement and am not giving any value for that field as its auto number. On the very next...
1
by: Ken | last post by:
Need help on the Auto Number or Identity Seed on the Oracle Database I got an Access database that need to be converted to Oracle 9i. Somehow the Trigger we created to simulate the "AUTO NUMBER"...
2
by: Tom | last post by:
I am trying to store information into a table that has an auto increment field. There is currently no data in the table. Using the code below I cannot insert data into the table. I get an error...
26
by: Dragon | last post by:
I have an Access 2003 .mde sitting on an SQL Server. The tables for the application also sit on the Server. I'm having a problem with ODBC on only one of about 10 machines. All the other machines...
4
by: Shahar | last post by:
Hi I need to get a field name 'ID'(that is an auto-number field) right after I add a new row to table, it's work like that: myCommand.ExecuteNonQuery(); myCommand.CommandText = "SELECT...
3
by: Robin Tucker | last post by:
Hi there, I have this really frustrating problem with Visual Studio (Microsoft Visual Basic .NET 2003 69586-335-0000007-18843). I have got used to using the autocomplete and auto indent...
1
by: books1999 | last post by:
Hi there, I have a problem with this css/div and i cannot work it out. I would like either container to be able to push the background box to grow but in Firefox it overflows. Can someone find a...
13
by: S.Dickson | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when...
1
by: NHNeedsHelp | last post by:
Hi, about to go nuts - I have a master form with 3 control buttons, user picks 1 for Const. job, 2 for Envir job and 3 for Geo job. Each button opens a subform containing the project number from...
7
by: ITAutobot25 | last post by:
My delete button is not working in my GUI and my due date is today before midnight. Can anyone show me how to correct this error? My assignment statement is below as well as 5 classes. InventoryGUI...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.