Javascript-Add currency to your given number.

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  2. <html>  
  3.    <head>  
  4.       <title>Sample Code</title>  
  5.       <script type="text/javascript">  
  6.          function AddCurrency(MyString)  
  7.          {           
  8.                       var objRegex = /^-?[0-9]+\.[0-9]+$/;  
  9.                       if(objRegex.test(MyString))   
  10.                      {  
  11.                             objRegex.compile('^-');  
  12.                             if (objRegex.test(MyString))  
  13.                            {           
  14.                                         MyString = '(' + MyString.replace(objRegex,' ') + ')';           
  15.                             }           
  16.                                   alert('$' + MyString);           
  17.                       }           
  18.                       else           
  19.                             alert(MyString);           
  20.          }           
  21.       </script>  
  22.    </head>  
  23.    <body bgcolor=#00ff00 alink=blue vlink=blue>  
  24.       <FORM name="windowEvent">  
  25.          Enter String : <input type="text" name="txtOriginal" /><br>  
  26.          <input type="button" value="Add Currency" name="btnAddCurrency" onClick="AddCurrency(txtOriginal.value);" />  
  27.       </FORM>  
  28.    </body>  
  29. </html>