473,654 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="ret urn(currencyFor mat(this,',','. ',event))" //(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="ret urn(currencyFor mat(this,',','. ',event))">

becomes

onKeyPress="ret urn(currencyFor mat(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="JavaS cript">

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.fromChar Code(whichCode) ; // take the key from keycode
if (strCheck.index Of(key) == -1) return false; // Unvalid key
len = fld.value.lengt h;
for(i = 0; i < len; i++)
if ((fld.value.cha rAt(i) != '0') && (fld.value.char At(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.index Of(fld.value.ch arAt(i))!=-1) aux += fld.value.charA t(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="ret urn(currencyFor mat(this,',','. ',event))">
</form>
</BODY>
</HTML>
Oct 16 '08 #1
2 2639
In comp.lang.javas cript message <48************ **********@read er1.news.t
in.it>, Thu, 16 Oct 2008 18:10:15, paolo <pa********@dig italminds.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.demo n.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.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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.dem on.co.ukwrote:
>In comp.lang.javas cript message <48************ **********@read er1.news.t
in.it>, Thu, 16 Oct 2008 18:10:15, paolo <pa********@dig italminds.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.demo n.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
1569
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 statement , I need to know which number it inserted in auto number field for that record?? What should be the logic??? Best Regards, dave
1
2573
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" on Access could not create the sequence number as soon as the value has been inserted. The sequence number can only be created after we go to the second line. Please see the trigger below. Is there anyway we could create a trigger that could...
2
12713
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 telling me that "Number of query values and destination fields are not the same." If I add a value for the auto increment field to the SQL String the data is entered into the table with no problems but obviously the auto increment field now...
26
6087
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 using my Access 2003 .mde see the linked tables without a problem. I've configured the User DSN (under Control Panel, Administrative Tools) tab to match what the other machines are set to, but this didn't work. I keep getting an error message...
4
10239
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 @@Identity"; // the auto-number fiels int iId = (int)myCommand.ExecuteScalar();
3
2467
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 features of this excellent source editor but recently it has only operated on some of my source files and not others. I have made sure the settings in "tools->options->text editor" are set correctly but to no avail. For example, hitting enter at the...
1
3050
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 solution to the problem contained in the code. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
13
4728
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 i type in the details. I have just moved over to mysql server with access as the front end. I have setup the sql tables with the customer number as autonumber. When i go into the form and add a new customer it does not generate the
1
2803
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 master form. The subform is basically a data entry form with a couple of pull down selections for the user to choose. The choices made on the subform auto fill a field called "New Project No" - That new number is compiled from the user choices, like...
7
6926
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 is the main class to begin execution. Thanks! • Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform the corresponding actions on the item name, the...
0
8290
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
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
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
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
5622
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
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1596
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.