Current location: Hot Scripts Forums » General Web Coding » JavaScript » number script


number script

Reply
  #1 (permalink)  
Old 09-09-03, 09:06 AM
deepforest deepforest is offline
New Member
 
Join Date: Sep 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy number script

Hello
i want to write money script but split with dot.
<input type="text" name="money">

example;
if i write 1000, java script change to 1.000
if i write 100000000, java script change to 100.000.000

(key press)

i can't write it.

please help me
thanks for replies
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-12-03, 06:59 AM
andreasberglind andreasberglind is offline
Newbie Coder
 
Join Date: Jul 2003
Location: Sweden
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Hi.

I thought your script sounded like fun, so I wrote it for you.
Here´s the whole html file.
Hope it works for you.

<html>
<head>
<title></title>
<script language="javaScript">
function money()
{
var sum = myForm.Text1.value;
var output=0;
var counter=0;

if(sum.length < 4)
{
document.write(sum);
}
else
{
for(var i=sum.length-1; i>=0; i--)
{
counter++;
if(i == sum.length-1)
{
output = sum.charAt(i);
}
else
{
output = sum.charAt(i)+output;
}
if(counter == 3 && i>0)
{
output = "."+output;
counter = 0;
}
}
document.write(output);
}
}
</script>
</head>
<body>
<form name="myForm">
<input type="text" name="Text1" value="0">
<input type="button" value="click" onclick="money();">
</form>
</body>
</html>

/Andreas
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-12-03, 10:01 AM
andreasberglind andreasberglind is offline
Newbie Coder
 
Join Date: Jul 2003
Location: Sweden
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
I improved the script a little, an also, here´s the .js file. That will make it a lot easier to read...
Attached Files
File Type: zip moneyscript.zip (602 Bytes, 8287 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a good review management script griz_fan Script Requests 10 07-29-07 06:08 AM
login script required lochie Script Requests 2 03-06-04 08:44 PM
New script needed PoliticalGateway Script Requests 0 09-22-03 01:57 PM
looking for a random number script ncben Script Requests 3 08-07-03 10:10 AM
Need help with a script boardpix PHP 7 06-09-03 12:37 AM


All times are GMT -5. The time now is 08:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.