Results 1 to 5 of 5

Thread: Currency Auto Format - Please Help

  1. #1
    Join Date
    Jun 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Currency Auto Format - Please Help

    Hi,

    I used the below code to auto format the currency input field. Now i need to add a $ sign in front of the numbers ($ sign inside the text box).

    http://javascript.internet.com/forms/auto-currency.html

    Would be great if you could let me know how to do this.

    Thanks.

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Code:
    <!-- TWO STEPS TO INSTALL AUTO CURRENCY:
    
      1.  Copy the coding into the HEAD of your HTML document
      2.  Add the last code into the BODY of your HTML document  -->
    
    <!-- STEP ONE: Paste this code into the HEAD of your HTML document  -->
    
    <HEAD>
    
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Original:  Mario Costa (mariocosta@openlink.com.br) -->
    <!-- Bug fix:   John Kiernan  -->
    
    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->
    
    <!-- Begin
    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 (Bug fixed)
    key = String.fromCharCode(whichCode);  // Get key value from key code
    if (strCheck.indexOf(key) == -1) return false;  // Not a valid 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;
    }
    //  End -->
    </script>
    
    </HEAD>
    
    <!-- STEP TWO: Copy this code into the BODY of your HTML document  -->
    
    <BODY>
    
    <form>
    Enter Value:
    <input type=text name=test length=15 onKeyPress="return(currencyFormat(this,',','.',event))">
    </form>
    
    <p><center>
    <font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
    by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
    </center><p>
    
    <!-- Script Size:  1.95 KB -->
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,982
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    You also may want to have a look at this thread, it is related but uses completely different code:

    http://www.dynamicdrive.com/forums/s...ead.php?t=4026
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Jun 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks a million tech_support

  5. #5
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    please help me

    output code top:
    1,234,456.78

    How to convert the code Top ?
    output code :
    12,345,678

Similar Threads

  1. JS currency converter?
    By NickNameDrive in forum JavaScript
    Replies: 3
    Last Post: 05-27-2010, 07:58 PM
  2. Resolved currency converting help
    By shas1280 in forum JavaScript
    Replies: 2
    Last Post: 05-16-2010, 09:07 AM
  3. Time field auto format and validation
    By chennaiMan in forum JavaScript
    Replies: 0
    Last Post: 04-14-2009, 11:56 AM
  4. Replies: 0
    Last Post: 05-10-2008, 05:13 AM
  5. number format to word format
    By Rockonmetal in forum PHP
    Replies: 2
    Last Post: 05-08-2008, 11:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •