Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 14th, 2004, 07:57 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default Numeric or currency field format

Hi

I have got an asp form with a textbox that accepts numeric caracters. At the moment have got a piece of Java that checks that the data is numeric before submitting to the SQL database. Now they want to change it to the following format e.g 1,000,000.00 How do I force the user on client side to input the data like this? I was thinking of a text box that format the value as the user type..Almost like an ATM machine. e.g 0,00.00 for default and as the user types it fills the zeros. Or a way to format and check the data before submission.

I hope this makes sense. Any ideas appreciated.

Regards
Marnus
 
Old July 14th, 2004, 08:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Lucky enough to get that so soon;)

Code:
<html>
<head>
<script language="javascript">
function CommaFormatted(amount)
{
    var delimiter = ","; // replace comma if desired
    var a = amount.split('.',2)
    var d = a[1];
    var i = parseInt(a[0]);
    if(isNaN(i)) { return ''; }
    var minus = '';
    if(i < 0) { minus = '-'; }
    i = Math.abs(i);
    var n = new String(i);
    var a = [];
    while(n.length > 3)
    {
        var nn = n.substr(n.length-3);
        a.unshift(nn);
        n = n.substr(0,n.length-3);
    }
    if(n.length > 0) { a.unshift(n); }
    n = a.join(delimiter);
    if(d.length < 1) { amount = n; }
    else { amount = n + '.' + d; }
    amount = minus + amount;
    return amount;
}
// end of function CommaFormatted()
</script>

</head>
<body>
Enter Number and tab out: <input type="text" name = "Num" value="" onblur="Javascript:FormattedNum.value=CommaFormatted(this.value);">
Formatted Number : <input type="text" name = "FormattedNum" value="">
</body>
</html>
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old July 14th, 2004, 08:22 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

Thanks! Will give it a shot.

Marnus





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set a value in datagrid to currency format? jhansib4u ADO.NET 0 December 12th, 2007 01:43 AM
Currency Format kdkcchoco ASP.NET 1.0 and 1.1 Professional 1 March 29th, 2007 08:13 AM
Currency Format heerajee Pro PHP 2 June 5th, 2006 02:24 AM
format currency civa Access 3 December 16th, 2005 03:50 AM
numeric format for a textbox Rudner Beginning VB 6 1 November 9th, 2004 02:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.