Advertisement

07.14.2003 at 07:15PM PDT, ID: 20678539
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

onkeyup auto currency format

Zone: JavaScript
Tags: currency, format
Ok... this is a little tricky!

I need a code that would allow user to input a value and as he/she types the number it should automatically insert commas and decimal points

for examlpe:

if I enter 1 the result would be 1.00
if I enter 1234 the result should be 1,234.00 and so on

also I would need to force the user to input the decimal point himself if the decimal was different then .00
so if he wanted to enter 1,234.67 the user would need to enter period and two decimals like .67 after the number
this has to use onkeyup, or keypress event

I'll give you enough of points for it I need it very soon

thanks in advance
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: Platini
Solution Provided By: AcklenX
Participating Experts: 5
Solution Grade: A
Views: 389
Translate:
Loading Advertisement...
07.14.2003 at 07:53PM PDT, ID: 8922216

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.14.2003 at 08:25PM PDT, ID: 8922316

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.14.2003 at 08:54PM PDT, ID: 8922448

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 01:35AM PDT, ID: 8923570

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 02:26AM PDT, ID: 8923832

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 03:12AM PDT, ID: 8924041

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 03:45AM PDT, ID: 8924177

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 04:36AM PDT, ID: 8924419

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 04:58AM PDT, ID: 8924584

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 05:11AM PDT, ID: 8924665

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 05:34AM PDT, ID: 8924814

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 05:49AM PDT, ID: 8924925

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 06:18AM PDT, ID: 8925132

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 01:54PM PDT, ID: 8929176

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 02:13PM PDT, ID: 8929351

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 02:24PM PDT, ID: 8929444

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 02:32PM PDT, ID: 8929501

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.15.2003 at 02:35PM PDT, ID: 8929525

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.16.2003 at 06:01AM PDT, ID: 8933850

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.16.2003 at 12:44PM PDT, ID: 8937426

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.16.2003 at 01:07PM PDT, ID: 8937628

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.16.2003 at 01:12PM PDT, ID: 8937685

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.16.2003 at 01:20PM PDT, ID: 8937755

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.16.2003 at 01:59PM PDT, ID: 8938135

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.18.2003 at 06:04AM PDT, ID: 8951379

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
07.14.2003 at 07:53PM PDT, ID: 8922216

Rank: Master

The math of decimals is easy enough to do, but do you expect the display to change in real-time, as each digit is entered?
Or will it be OK for the user to enter the value, then on finishing, format the string in the input box?
Where does the onKeyUp come in?  Is it after each key, or after the event that finishes the input?

Since you require a very specific routine, be more specific about the exact sequence of events, as a user types.
 
07.14.2003 at 08:25PM PDT, ID: 8922316
/*
i think the problem that you are going to run into is the old 'onkeyup-value swap-refocus-oops' problem.  that is if you change the field the focus will shift to the end of the field (not where you want to be, especially if you are focing a decimal, or editing a number you already entered).  onblur works much better. (short of non-cross browser shiftiness, i'm not sure how to get that effec - and even then it would be difficult) anyway i dusted off some old code and this should do the trick (onblur, though i included the onkeyup so you can see the problem with your request)
*/

<script>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////BEGIN NUMBER FORMATTING/////////////////////////
////////////////////////////////////////////////////////////////////////////////
      
      function formatCurrency(sNumber,groupSeparator,currencySymbol,fractionMark,precision)
      {
            groupSeparator       = groupSeparator || ',';                                                // set default groupSeparator to a comma (,)
            currencySymbol      = currencySymbol || '$';                                                // set default currencySymbol to dollars ($)
            fractionMark      = fractionMark || '.';                                                        // set default fractionMark to a period (.)
            precision != 0 ? precision = (precision || 2): null;            // set the default precision to 2 decimal places (extra test allows for 0 to override - exactly what you you would expect)
            
            number = formatNumber(sNumber,groupSeparator,currencySymbol,fractionMark,precision)
            return number;
      }
      
      function formatNumber(sNumber,groupSeparator,currencySymbol,fractionMark,precision)
      {
            groupSeparator       = groupSeparator || ',';                                                // set default groupSeparator to a comma (,)
            currencySymbol      = currencySymbol || '';                                                      // set default currencySymbol to dollars ($)
            fractionMark      = fractionMark || '.';                                                            // set default fractionMark to a period (.)
            precision != 0 ? precision = (precision || 2): null;            // set the default precision to 2 decimal places (extra test allows for 0 to override - exactly what you you would expect)
            
            sUnformattedNumber = unformatNumber(sNumber);                                                                                    
            sRoundedNumber = Math.round(sUnformattedNumber*Math.pow(10,precision))/Math.pow(10,precision)+'';       // round the number AND cast it to a string
            var whole = getWholeNumber(sRoundedNumber);
            var decimal = getDecimalNumber(sRoundedNumber);
            
            whole = addCommas(Math.abs(whole),groupSeparator);
            decimal = addZeros(decimal,precision);      
            sFormattedNumber = precision > 0 ?  (currencySymbol + whole + fractionMark + decimal) : (currencySymbol + whole + decimal);      
            if (isNegative(sNumber))
            {
                  sFormattedNumber = '-' + sFormattedNumber;
            }
            return sFormattedNumber;
      
            /*PRIVATE METHODS - formatNumber()*/
                  function addCommas(number,groupSeparator)
                  {
                        var groupSeparator = (groupSeparator || ',');
                        if (number && number !=0)
                        {
                              number +='';
                              if (number.length > 3)
                              {
                                var mod = number.length % 3;
                            var output = (mod > 0 ? (number.substring(0,mod)) : '');
                            for (i=0 ; i < Math.floor(number.length/3) ; i++) {
              if ((mod ==0) && (i ==0))
              {
                                output+= number.substring(mod+3*i,mod+3*i+3);
              }      
                          else
                                          {
                                                output+= groupSeparator + number.substring(mod+3*i,mod+3*i+3);
                              }
                                    }
                            return (output);
                          }
                              return number+='';
                        }
                        if (number == 0)
                              return number+='';
                        return '';
                  }
                  
                  function addZeros(decimal,precision)
                  {
                        if (precision)
                        {
                              if (decimal.toString().length == 0)
                                    decimal = 0;
                              var zeros='';
                              numberOfZeros = (precision - decimal.toString().length);
                              for (z=0 ; numberOfZeros > z ; z++)
                                    zeros+='0';
                              return decimal + zeros;
                        }
                        return '';
                  }

                  function getDecimalNumber(sNumber)
                  {
                        sNumber = sNumber.toString();
                        if (sNumber.toString().indexOf('.')!= -1)
                        {
                              sWholeNumber = sNumber.substring(sNumber.indexOf('.')+1,sNumber.length);
                        }
                        else
                              sWholeNumber = '';
                        return sWholeNumber;
                  }
                  
                  function getWholeNumber(sNumber)
                  {
                        if (sNumber)
                        {
                              sNumber = sNumber.toString();
                              if (sNumber.toString().indexOf('.')!= -1)
                                    sWholeNumber = sNumber.substring(0,sNumber.indexOf('.'));
                              else
                                    sWholeNumber = sNumber;
                              return sWholeNumber;
                        }
                        return '0';
                  }
            /*PRIVATE METHODS - formatNumber()*/
      }
      
      function isNegative(sNumber)
      {
            return sNumber.toString().indexOf("-") == 0;
      }
      
      function unformatNumber(sNumber,sFractionMark)
      {
            sFractionMark = (sFractionMark || '.');
            sNumber = sNumber.toString();
            if(sNumber || sNumber == 0)
            {
                  var aNumber = sNumber.split(sFractionMark);
                  
                  if (aNumber[1])
                  {
                        var sWholeNumber = removeNonDigits(aNumber[0]);                  
                        var sDecimalNumber = removeNonDigits(aNumber[1]);
                        if (sDecimalNumber == '')
                        {
                              iUnformattedNumber = sWholeNumber - 0;
                              if (sWholeNumber == '') return '';
                        }
                        iUnformattedNumber = sWholeNumber + '.' + sDecimalNumber - 0;
                  }
                  else
                  {
                        var sUnformattedNumber = removeNonDigits(sNumber);
                        if (sUnformattedNumber == '')
                        {
                              return sUnformattedNumber;
                        }
                        var iUnformattedNumber = sUnformattedNumber - 0;
                  }
                  if (isNegative(sNumber))
                        iUnformattedNumber = '-' + iUnformattedNumber - 0;
                  return iUnformattedNumber;
            }
            return sNumber;
    /*PRIVATE METHODS - unformatNumber()*/
          function removeNonDigits(sMixedString)
      {
        var sNumbersOnly = sMixedString.replace(/[^0-9]/g,'');
        return sNumbersOnly;
      }
    /*PRIVATE METHODS - unformatNumber()*/
      }
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////END NUMBER FORMATTING///////////////////////////
////////////////////////////////////////////////////////////////////////////////


</script>


 
07.14.2003 at 08:54PM PDT, ID: 8922448

Rank: Master

Platini --

Since you needed it "SOON", here it is -- this is a complete formatting routine from Michel Plungjan's Instant JS book.

You can just remove the parts you don't want.  It is robust (sorry AcklenX, I couldn't get yours to work right).

e.g. remove the portion that writes out the number.  If you don't want a click button, choose AcklenX's "onBlur" event.

However, I found the on-blur much less intuitive than clicking a "complete" button, which is very obvious to the reader.

Also, take careful note, you can TIME the input, so that it will format after a certain "setTimeOut(1000)" -- e.g. one second.

That way, a significant pause is guaranteed to format the text field.  This will totally avoid the focus issue AcklenX mentions.

Here it is:

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META http-equiv="Content-Style-Type" content="text/css">
<title>Number Utilities</title>

<script language="JavaScript"><!--
function round(number,x) {
  return Math.round(number * Math.pow(10,x)) / Math.pow(10,x);
}

function cents(amount) {
  amount -= 0;

  amount = round(amount, 2);

  if (amount == 0)
    amount = '.00';
  else if (amount == Math.floor(amount))
    amount += '.00';
  else if (amount*10 == Math.floor(amount*10))
    amount += '0';

  return '' + amount;
}

function commas(integer) {
  integer = '' + Math.round(integer);

  if (integer.length > 3) {
    var mod = integer.length%3;

    var output = (mod > 0 ? (integer.substring(0,mod)) : '');

    for (i=0 ; i < Math.floor(integer.length/3) ; i++) {
      if ((mod ==0) && (i ==0))
        output+= integer.substring(mod+3*i,mod+3*i+3);
      else
        output+= ',' + integer.substring(mod+3*i,mod+3*i+3);
    }
    return output;
  }
  return integer;
}

function monetary(amount) {
  var integer = Math.floor(amount);
  var floating = amount - integer;

  return commas(integer) + cents(floating);
}

var numbers = new Array(
  '','one','two','three','four','five','six','seven',
  'eight','nine','ten','eleven','twelve','thirteen','fourteen',
  'fifthteen','sixteen','seventeen','eighteen','nineteen',
  '','','twenty','thirty','fourty','fifty','sixty', 'seventy',
  'eighty','ninety'
);

function tu(u) {
  var t = 0;
  if (u>=20) t = (u - u % 10) / 10, u = u - (u - u % 10);
  return numbers[t+20] + ((t>0 && u>0) ? '-' : '') + numbers[u];
}

function htu(number) {
  var hs = (number - number % 100) / 100;
  var tus = number - hs * 100;

  return tu(hs) + (hs>0 ? ' hundred' : '') +
         (tus>0 && hs>0 ? ' ':'') + tu(tus);
}

function monetaryString(input) {
  var dollars = Math.floor(input - 0);
  var cents = Math.floor(input*100 - dollars*100);

  var billions = (dollars - dollars % 1000000000) / 1000000000;
  dollars  -= billions * 1000000000;
  var millions = (dollars - dollars % 1000000) / 1000000;
  dollars  -= millions * 1000000;
  var thousands = (dollars - dollars % 1000) / 1000;
  dollars -= thousands * 1000;

  var o = '';

  o += HTU(billions, ' billion', ', ');
  o += HTU(millions, ' million', ', ');
  o += HTU(thousands, ' thousand', ', ');
  o += HTU(dollars, ' dollars', ', ');
  o += HTU(cents, ' cents', ' and ');

  and = false;

  return o.substring(0,1).toUpperCase() + o.substring(1);
}

var and = false;

function HTU(number, text, add) {
  if (number <= 0) return '';
  var output = '';
  if (and) output += add;
  output += htu(number) + text;
  and = true;
  return output;
}
//--></script>

</head>



<form>







<input type="button" value="Convert"
  onClick="this.form.o1.value=monetary(this.form.i.value);
    this.form.o2.value=monetaryString(this.form.i.value)">


<textarea name="o2" rows="5" cols="70" wrap="virtual">
</textarea>
</form>

</body>
</html>

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

That does what you want.  Just remove the parts you don't want, and try the time out, repeatedly calling the function.

You can take it from there, it will give you some practice!!!!

Cheers
Assisted Solution
 
07.15.2003 at 01:35AM PDT, ID: 8923570

Rank: Master

try this way:

<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT>

      function FormatCurrency(objNum)
      {
            var num = objNum.value;
            var ent, dec;
            if (num != '' && num != objNum.oldvalue)
            {
                  num = MoneyToNumber(num);
                  if (isNaN(num))
                  {
                        objNum.value = objNum.oldvalue;
                  }
                  else
                  {
                        if (event.keyCode == 190 || !isNaN(num.split('.')[1]))
                        {
                              objNum.value = AddCommas(num.split('.')[0])+'.'+num.split('.')[1];
                        }
                        else
                        {
                              objNum.value = AddCommas(num.split('.')[0]);
                        }
                        objNum.oldvalue = objNum.value;
                  }
            }
      }
      
      function MoneyToNumber(num)
      {
            return (num.replace(/,/g, ''));
            
      }

      function AddCommas(number)
      {
            number = '' + number;
            if (number.length > 3)
            {
                  var mod = number.length % 3;
                  var output = (mod > 0 ? (number.substring(0,mod)) : '');
                  for (i=0 ; i < Math.floor(number.length / 3); i++)
                  {
                        if ((mod == 0) && (i == 0))
                        {
                              output += number.substring(mod + (3 * i), mod + (3 * (i + 1)));
                        }
                        else
                        {
                        output += ',' + number.substring(mod + (3 * i), mod + (3 * (i + 1)));
                        }
                  }
                  return (output);
            }
            else
            {
                  return (number);
            }
      }
</SCRIPT>
</HEAD>




</BODY>
</HTML>


hope it helps ya

almabres
Assisted Solution
 
07.15.2003 at 02:26AM PDT, ID: 8923832

Rank: Genius

:) Quite some postings here...
I actually made another addComma

function addComma(num) {
   numArr=new String(num).split('').reverse()
   for (i=3;i<numArr.length;i+=3) {
     numArr[i]+=','
   }
   return numArr.reverse().join('');
}
alert(addComma(100000000))

Michel
 
07.15.2003 at 03:12AM PDT, ID: 8924041

Rank: Master

hi, here comes an improved version: it works in NS too (I've tested it in NS7, don't know about former versions but I guess it works fine too at least in NS6)  and using Michel's AddComma function (Michel: I really like your function, it's brief and clear, much better than mine, thanx)
here is:

<HTML