View Full Version : number script
deepforest
09-09-03, 09:06 AM
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
andreasberglind
09-12-03, 06:59 AM
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
andreasberglind
09-12-03, 10:01 AM
I improved the script a little, an also, here´s the .js file. That will make it a lot easier to read...
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.