Results 1 to 4 of 4

Thread: I need help with my JavaScript

  1. #1
    Join Date
    Dec 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation I need help with my JavaScript

    Hi I need help with this javascript code. Once you are able to figure out please email me the Correct Code. My email address is "mhoque@isda.org"

    It is just simple addition that will be needed to up into currency format for example:


    Here is how it should add up with the currency format using commas and dollar sign. And it is not doing that.

    $10,000.10
    $10,000.11
    $10,000.12
    $10,000.13
    -------------
    $40,000.46



    Here is my Code below: please help


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>test currency</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <SCRIPT LANGUAGE="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>

    <SCRIPT LANGUAGE="JavaScript">
    function CollateralAssets()
    {
    var collreceivedUSD = document.submitform.collreceivedUSD.value
    var collreceivedEUR = document.submitform.collreceivedEUR.value
    var collreceivedGBP = document.submitform.collreceivedGBP.value
    var collreceivedJPY = document.submitform.collreceivedJPY.value
    document.submitform.TotalCollateralAssetsReceived.value=collreceivedUSD*1+collreceivedEUR*1+collreceivedGBP*1+collreceivedJPY*1
    }
    </script>
    </head>

    <body>
    <form name="submitform">
    <table width="100%" border="1" bordercolor="#000033">
    <tr valign="top" bgcolor="#000040">
    <td width="16%"> <div align="center" class="style4"><strong><font size="2" face="Arial"><font color="#FFFFFF">Amount
    received<br>
    (USD)</font></font></strong></div></td>
    </tr>
    <tr>
    <td bgcolor="#E9ECD9"><div align="center"> <font size="2" face="Arial">
    <input name="collreceivedUSD" type="text" id="collreceivedUSD" value=".00" size="15" onBlur="CollateralAssets();this.value=formatCurrency(this.value);">
    </font></div></td>
    </tr>
    <tr>
    <td bgcolor="#E9ECD9"><div align="center"> <font size="2" face="Arial">
    <input name="collreceivedEUR" type="text" id="collreceivedEUR" value=".00" size="15" onBlur="CollateralAssets();this.value=formatCurrency(this.value);">
    </font></div></td>
    </tr>
    <tr>
    <td bgcolor="#E9ECD9"><div align="center"> <font size="2" face="Arial">
    <input name="collreceivedGBP" type="text" id="collreceivedGBP" value=".00" size="15" onBlur="CollateralAssets();this.value=formatCurrency(this.value);">
    </font></div></td>
    </tr>
    <tr>
    <td bgcolor="#E9ECD9"><div align="center"> <font size="2" face="Arial">
    <input name="collreceivedJPY" type="text" id="collreceivedJPY" value=".00" size="15" onBlur="CollateralAssets();this.value=formatCurrency(this.value);">
    </font></div></td>
    </tr>
    <tr>
    <td bgcolor="#E9ECD9"><div align="center"></div></td>
    </tr>
    <tr>
    <td bgcolor="#0000FF">
    <div align="center"><font size="2" face="Arial">
    <input name="TotalCollateralAssetsReceived" type="text" id="TotalCollateralAssetsReceived" onBlur="this.value=formatCurrency(this.value);" value=".00" size="15">
    </font></div></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Man, oh, man. This is the most EASY script I could solve in my whole life. Yeah, um, you aren't allowed to add characters with characters. yeah, um, it is like adding $ + $. Simply make the number only with INTEGERS and display it w/ a $ sign.

    -magicyte

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hey, he's new-- be nice. Plus, "characters with characters" makes little sense in your post.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Hey, he's new
    Ha ha ha. He posted this script in 2004 and has only posted TWICE. I don't think he's new...

    But, sure, I'll be nice. I'm sorry if I offended anybody. Plus, characters plus characters (what (s)he is doing is (s)he's adding $11323 with $348. They are unquoted, meaning they aren't strings and are only allowed to hold name of variables and integers. (S)he used a character in there...which isn't allowed) makes sense to me (but now that I've explained it, it should make sense). Unless you are using a type-cast in C or C++, this script base wouldn't work.

    -magicyte

    P.S. -Um, does any moderator know why my thing says I'm a Regular Coder, but my img thing says Junior Coder. Any help!?

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
  •