Sireesha
asked on
Problem using Onkeypress event on a text control
I have a text control in an ASP page in which user can enter alphanumeric data.I want to change lower case letters to uppercase once user enters a character and i am doing that using onkeypress event and it works fine but,the problem is suppose i have a value like CD-1-02-4010 in the text box and i think that i have entered wrong value and try to change any character in the value it is appending at the end of the value.It is not being entered in the right place.How do i overcome this
Here how i have
<form id = "frm">
<input type = text id = "txtTest" onkeypress = "Vbscript:CaseConversion"> </input>
</form>
<script language = "vbscript">
sub CaseConversion
frm.txtTest.value = ucase(frm.txttest.value)
end sub
</script>
Above Code works but,it doesn't let me change the value.Some one please help.Thanks
Here how i have
<form id = "frm">
<input type = text id = "txtTest" onkeypress = "Vbscript:CaseConversion">
</form>
<script language = "vbscript">
sub CaseConversion
frm.txtTest.value = ucase(frm.txttest.value)
end sub
</script>
Above Code works but,it doesn't let me change the value.Some one please help.Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
On my computer it runs just fine, what do you mean by the first character. The first one you typed or the character 'a'?
Try this
<form id = "frm">
<input type = text id = "txtTest" onkeypress = "Vbscript:CaseConversion"> </input>
</form>
<script language = "vbscript">
sub CaseConversion
if window.event.keyCode > 96 and window.event.keyCode < 123 then
window.event.keyCode = cint(window.event.keyCode) - 32
end if
end sub
</script>
Try this
<form id = "frm">
<input type = text id = "txtTest" onkeypress = "Vbscript:CaseConversion">
</form>
<script language = "vbscript">
sub CaseConversion
if window.event.keyCode > 96 and window.event.keyCode < 123 then
window.event.keyCode = cint(window.event.keyCode)
end if
end sub
</script>
ASKER
It still doesn't work.I mean fist character.What ever character i type first.It is strange.I will keep trying and let you know.Please let me know if you can think of anything else in the mean while.Thanks
ASKER
It works fine now.I had an if condition before i think that was causing that to happen.Any way thanks alot and i will close the close in a while once i make sure everything is fine.Thanks alot
So the points are mine?
:-)
:-)
ASKER
Yes,they are your's i will close it right a way.Thanks again
ASKER
it is working for all the characters but for the first character.Any suggestions please
thanks