Form mask...

They have: 31 posts

Joined: Dec 1999

I am trying to set up a form which will actually mask the entered data.
For example, If the user enters data in an <input type=text> which is called Price, like this:
1000000, I want a Javascript or an asp routine which will covert it to :
1.000.000. I know that there is a 'formatCurrency' function, or something in ASP, but my host has US Regional settings which will show 1,000,000. However, I want to use . instead of , .... Is there any way to do this using a Javascript which will work with both IE and N, or any asp function?

Thanx a lot

Coddy

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi

Not sure if it's what you want, but I have some masking routines at my site (along with explanations) I also have a currency formatting script ($1,999,999.99)

Vinny GrassBlade: cut&paste javascript

Where the world once stood
the blades of grass cut me still

They have: 47 posts

Joined: Jan 2000

You can do the parsing with ASP. Check the following, if the number is greater then 999, put a '.' in front of the last three digits, and so on. The parsing should be pretty straightforward.

Eugene Grinberg http://www.interprosolution.com
FREE Tools & Services for Webmasters

They have: 31 posts

Joined: Dec 1999

Eugene,
Can you give me an example?

Thanx a lot

Coddy

They have: 47 posts

Joined: Jan 2000

Suppose a user entered 1234567.89 and you need to convert it to $1.234.567.89

First Method:
You could use a 'formatCurrency' function to covert it to $1,234,567.89 and then replace all commas with a '.'

Second Method:
You can implement the following algorithm (I tested it and had no problems with it, but if you find one, be sure to tell me, and I'll fix it):

Function ToCurrency(pAmount)
Dim vTemp, vCurrency, i, vOffset

vTemp = CStr(Fix(CDbl(pAmount)))

vOffset = Len(vTemp) - Fix(Len(vTemp) / 3) * 3

For i = 0 To Round(Len(vTemp) / 3)
If i = 0 Then
vCurrency = Left(vTemp, vOffset)
End If

If i <> Round(Len(vTemp) / 3) Then
If Len(vCurrency) <> 0 Then
vCurrency = vCurrency & "."
End If

vCurrency = vCurrency & Mid(vTemp, 1 + vOffset + i * 3, 3)
End If
Next

If Len(vTemp) < Len(pAmount) Then
vCurrency = vCurrency & Right(pAmount, Len(pAmount) - Len(vTemp))
End If

vCurrency = "$" & vCurrency

ToCurrency = vCurrency
End Function

Eugene Grinberg
http://www.interprosolution.com
FREE Tools & Services for Webmasters

[This message has been edited by Eugene Grinberg (edited 13 February 2000).]

They have: 31 posts

Joined: Dec 1999

Thanks Eugene!
If it's not a trouble, can you describe the first method?(Using FormatDate- change , with a .)

Thanx a lot!!!

Coddy

They have: 47 posts

Joined: Jan 2000

There is a 'formatCurrency' function in ASP which would convert 1000000 to $1,000,000.00

All you need to do is to change ',' to '.'

This can be done using the following:

Function ToCurrency2(pAmount)

ToCurrency2 = Replace(FormatCurrency(pAmount), ",", ".")

End Function

This is a definitely easier algorithm.
I hope this helped you.

Eugene Grinberg http://www.interprosolution.com
FREE Tools and Services for Webmasters

They have: 31 posts

Joined: Dec 1999

FANTASTIC!!!

Thanx very very much!!!!

Nick

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.