|
-
Aug 12th, 2012, 02:08 PM
#1
[RESOLVED] Put a comma on last 2 digits while typing in a textbox.
Hi.I don't have a VS in front of me but i would be needing this one next week when i start working again,so i thought i would be prepared.What i want to do is put a comma "," right before the last 2 digits.So i am thinking of ajax masked edit extender but i don't have VS here so i can't do the testings.If it does not have the exact feature i was thinking of some custom javascript-jquery function .Finally a regex to clear out the wrong formats-characters again if masked extender does not work.
My formatting should be like this: 1234567 to 12345,67 , 1 to 1,00 etc.I should be trying this myself but i appreciate a head up from anyone of you so i would have it ready to go next week when i get my hands to Visual Studio any help would be appreciated.If doable, i would prefer the mask for the masked extender.
Thanks.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Aug 12th, 2012, 09:09 PM
#2
Re: Put a comma on last 2 digits while typing in a textbox.
Id just use JS on the keyup event of the textbox, would only take a few lines so if you don't use the masked extender (I never have so no comment) I'd be happy to try my hand and post the JS.
The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded. 
-
Aug 12th, 2012, 11:08 PM
#3
Re: Put a comma on last 2 digits while typing in a textbox.
Hey.I have no problem with js or jquery, i have seen some samples and saved them in order for me to try them next week when i would be able to have a Visual Studio enabled computer.So,of course, feel free to post any script.Thanks.
P.S. This is for textboxes that cover doctors general examination values on patience so i suppose it won't need a dot also(p.e. it would be 1000,00 and not 1.000,00) i am just saying that because i haven't been given that exact information and everyone here(including me) are on vacation and i cannot find anyone till the end of the month to clarify this info.So if you have any opinion or experience on this do also advice.But i believe no dot is needed.Thanks again.
P.S.2 Unfortunately i would be going on another island so no free WIFI as off,err,8 hours from now,so i would probably be able to see this on Friday.So take your time.Going to bed... 
Edit.Sorry i forgot this.I would like, if possible the comma to appear at the first keyup so when someone writes 1 it would be ,01 when it presses 1 again would be ,11 then again would be 1,11 and again 11,11 etc.
Last edited by sapator; Aug 12th, 2012 at 11:14 PM.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Aug 13th, 2012, 01:51 AM
#4
Re: Put a comma on last 2 digits while typing in a textbox.
Hey Sap,
Here is an example of this being done when the focus is lost of the TextBox:
http://scottonwriting.net/sowblog/ar...ormatting.aspx
Which I am sure could be modified to act as you require.
Hope that helps!
Gary
-
Aug 13th, 2012, 04:43 AM
#5
Re: Put a comma on last 2 digits while typing in a textbox.
 Originally Posted by sapator
Edit.Sorry i forgot this.I would like, if possible the comma to appear at the first keyup so when someone writes 1 it would be ,01 when it presses 1 again would be ,11 then again would be 1,11 and again 11,11 etc.
well that complicates matters but check this out
Code:
<script type="text/javascript">
function formatNumber(txt){
var input = txt.value
var lgth = input.length
var lastDigit = input.charAt(lgth-1)
if (isNaN(lastDigit)){
//char is not a number
txt.value = input.substr(0,lgth-1)
alert("Numbers Only")
}else{
//format text
num = input.replace(",", "") //remove comma
if (num.substr(0,1) == 0){
num = num.substr(1,lgth-1) //remove 0 from start
}
if (num.length == 0){
//enterd 0 as first char
txt.value = ""
//alert("Can't start with 0")
}else if (num.length == 1){
txt.value = ",0" + num
}else if (num.length == 2){
txt.value = "," + num
}else{
last2Digits = num.substr(lgth-3,lgth-1)
firstDigits = num.substr(0,lgth-3)
txt.value = firstDigits + "," + last2Digits
}
}
}
</script>
on the textbox add onkeyup="formatNumber(this)"
The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded. 
-
Aug 13th, 2012, 06:37 PM
#6
Re: Put a comma on last 2 digits while typing in a textbox.
Apparently being drunk and writing stuff is not very good advisor as i actually am leaving tomorrow for the other island 
So thank you i will try them next week back home.
brin one observation.I saw on the script that zero cannot be the first char.This is not the case because someone may want a value to be p.x. 0,06 .
Thanks again will report when i try them.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Aug 14th, 2012, 01:56 AM
#7
Re: Put a comma on last 2 digits while typing in a textbox.
-
Aug 20th, 2012, 12:27 AM
#8
Re: Put a comma on last 2 digits while typing in a textbox.
Hey.So i just had a quick run and i am using masked extender with a filter.Thanks.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Aug 20th, 2012, 12:49 AM
#9
Re: [RESOLVED] Put a comma on last 2 digits while typing in a textbox.
Noice! Glad to hear that you got it working!
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|