Results 1 to 1 of 1

Thread: Numeric Textbox with format

  1. #1
    Join Date
    Oct 2011
    Posts
    16

    Numeric Textbox with format

    Dear Experts

    I have following codes

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="language" content="english"> 
    <meta http-equiv="Content-Style-Type" content="text/css">
    
    <title>Numeric Textbox Sample</title>
    
    <style type="text/css">
    #box1	{width:200px;height:170px;border:1px solid green;background:#e3eeff;padding-top:20px;}
    
    .button	{width:100px;margin-top:0px;}
    
    body {
        margin:0;
    margin-top:100px;
    	 }
    </style>
    
    <script language="javascript">
    
    function NumericDotOnly()
    {
    var key = window.event.keyCode; 
    
    if (((key >47) && (key <58)) || (key==46))
    window.event.returnValue = true;
    else 
    window.event.returnValue = false;
    }
    
    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 onload="form2.text1.focus()" >
    <center>
    <p>I need following format<br>
    99,999,999.99<br>
    </p>
    <div id="box1">
    		<form name=form2>
    		<table width="100%" border="0" cellpadding="0" cellspacing="0">
    		<tr><td>Amount</td> 
    
    <td><input type=text name=text1 size=15 value="" onkeypress="form2.text1.value=NumericDotOnly
    
    ()";onblur="form2.text1.value=formatCurrency(this.value)"> </td></tr>	
    
    	<tr><td>Tax</td> <td><input type=text name=text2 size=15 value="" 
    
    onkeypress="form2.text2.value=NumericDotOnly()";onblur="form2.text2.value=formatCurrency(this.value)"></td></tr>		
    <tr><td>Result</td><td><input type=text name=text3 size=15 value="" disabled></td></tr>
    
    		</table>
    		<hr>
    		<input class="button" type=button name=command1 value="Plus" 
    
    onclick="form2.text3.value=parseFloat(form2.text1.value)+parseFloat(form2.text2.value)"><br>
    
    		<input class="button" type=button name=command8 value="Focus" 
    
    onclick="form2.text1.select()";"form2.text1.focus()"><br>
    		<input class="button" type=reset name=command9 value="Reset">
    	
    </form>
    </div>
    
    </center>
    </body>
    </html>
    Please help me to apply following format

    99,999,999.99

    Thanks in advance
    Last edited by tqm1; 22 Dec 2011 at 03:17 AM.

Similar Threads

  1. using strrpos to find numeric charater in string
    By fuston05 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 13 Oct 2010, 06:21 PM
  2. copy text from textbox to new page?
    By deluxe01 in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 31 Jul 2009, 01:59 PM
  3. Display textbox value in a div
    By jaysnanavati in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 19 Jun 2009, 01:08 PM
  4. ASP Textbox width
    By keno2113 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 27 Mar 2008, 10:41 AM

Posting Permissions

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