HTML Help
HTML Help Central . com

» Online Users: 67

1 members and 66 guests
Most users ever online was 695, 02-16-2011 at 07:01 AM.

» Site Navigation

 > FAQ

» Domains For Sale

Results 1 to 2 of 2
  1. #1
    venomdesign Guest

    Post Javascript Confirm Format

    Is there a way to format currency in a javascript confirm window? Or can there only be numbers and no currency formatting. Probably can figure it out, but here is an example. For and auction suppose you put a bid of 9867659, and a confim window pops up and states are you sure of this bid, $9,867,659.00. I would like it to be converted with all the comas and currency sign, but I can only get it to show up like this, 9867659. Any help would be great.

    Thanks

  2. #2
    Join Date
    Mar 2005
    Location
    Singapore
    Posts
    1,766
    Here's a script, and how you can use it for the text fields:
    HTML Code:
    <html>
    <head>
    <title>Currency Formatter</title>
    <script type="text/javascript"><!--
    function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '$' + num + '.' + cents);
    }
    //--></script>
    </head>
    
    <body>
    <form name="currencyform">
    Enter a number then click the button: <input type=text name=input size=10 value="1000434.23" />
    <input type=button value="Convert" onclick="this.form.input.value=formatCurrency(this.form.input.value);" />
    <br /><br />
    or enter a number and click another field: <input type="text" name="input2" size="10" value="1000434.23" onBlur="this.value=formatCurrency(this.value);" />
    </form>
    </body>
    </html>

Similar Threads

  1. javascript confirm function
    By deba in forum Javascript / AJAX / VBScript
    Replies: 5
    Last Post: 02-07-2008, 05:29 AM
  2. Javascript Confirm
    By uwdoug79 in forum Javascript / AJAX / VBScript
    Replies: 16
    Last Post: 11-18-2003, 02:31 PM
  3. javascript confirm
    By rafabc in forum Javascript / AJAX / VBScript
    Replies: 1
    Last Post: 11-04-2003, 04:52 AM
  4. javascript confirm
    By rafabc in forum Javascript / AJAX / VBScript
    Replies: 1
    Last Post: 11-03-2003, 06:43 PM
  5. javascript confirm
    By lambda in forum Javascript / AJAX / VBScript
    Replies: 1
    Last Post: 05-03-2001, 07:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Powered by vBadvanced CMPS v4.1.1