?
Solved

Problem using Onkeypress event on a text control

Posted on 2002-06-10
7
Medium Priority
?
290 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:Sireesha
  • 4
  • 3
7 Comments
 
LVL 12

Accepted Solution

by:
Wouter Boevink earned 200 total points
ID: 7069294
Your problem is then when a key is pressed your function is executed, it substitutes the value of a input box and then returns after which the character gets in the box.

try using this

<form id = "frm">
<input type = text id = "txtTest" onkeypress = "Vbscript:CaseConversion"></input>
</form>
<script language = "vbscript">
   sub CaseConversion
     if window.event.keyCode >= 97 and window.event.keyCode <= 122 then
          window.event.keyCode = window.event.keyCode - 32
       end if
   end sub
</script>

if a user types any character from lowercase 'a' to 'z' it will be substituted by uppercase 'A' - 'Z'
0
 

Author Comment

by:Sireesha
ID: 7070123
wboevink,
          it is working for all the characters but for the first character.Any suggestions please
thanks
0
 
LVL 12

Expert Comment

by:Wouter Boevink
ID: 7070170
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>


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Sireesha
ID: 7070188
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
0
 

Author Comment

by:Sireesha
ID: 7070220
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
0
 
LVL 12

Expert Comment

by:Wouter Boevink
ID: 7070509
So the points are mine?

:-)
0
 

Author Comment

by:Sireesha
ID: 7070519
Yes,they are your's i will close it right a way.Thanks again
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question