Solved

Problem using Onkeypress event on a text control

Posted on 2002-06-10
7
244 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 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Sireesha
Comment Utility
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
Comment Utility
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
Comment Utility
So the points are mine?

:-)
0
 

Author Comment

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now