Results 1 to 8 of 8

Thread: upper case

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    London
    Posts
    678

    upper case

    What is the easiest way to convert the text in a text box to upper case as you are typing the letters?
    Thanks

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    You would have to use javascript to do that by capturing the keypressdown event.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    London
    Posts
    678
    I believe there is no keypressdown event.

  4. #4
    New Member
    Join Date
    Jun 2004
    Posts
    10
    Code:
    <html>
    <head>
    <script language="javascript">
    function MakeCaps(t)
      {
       var tmp;
       tmp = t.value;
       t.value = tmp.toUpperCase();
      }
    </script>
    </head>
    <body>
    <form name=form1>
    <input type=text name=txtUsername onkeyUp="javascript:MakeCaps(this);">
    </form>
    </body>
    </html>

  5. #5
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    Originally posted by fmardani
    I believe there is no keypressdown event.
    I meant just capturing the key events, such as key down, key up, key press, etc....
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  6. #6
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: upper case

    Is there a way to do this using an asp control, rather than a html control?

  7. #7
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: upper case

    Maybe somebody can help me with the following javascript:
    Code:
    		<script language=javascript>
    		function inspectEvent(evt){
    		if (evt.keyCode == 13)return false;
    		if (evt.keyCode > 96 && evt.keyCode < 123)return evt.keyCode - 32;
    		}</script>
    The first if disables the enter button. I'm trying to use the same function to trap lowercase keystrokes, and convert them to upper case.

  8. #8
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: upper case

    For anybody interested:

    Code:
    <HEAD>		
                   <script language=javascript>function inspectEvent(evt){
    		if (evt.keyCode >= 97 && evt.keyCode <= 122)
    		{
    		Alpha=String.fromCharCode(evt.keyCode).toUpperCase();
    		evt.srcElement.value=evt.srcElement.value + Alpha;
    		return false;
    		}
    		else if (evt.keyCode == 13)return false;
    		}</script>
    </HEAD>
    VB Code:
    1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.    
    3.         If Not IsPostBack Then
    4.                 Form1.Attributes.Add("onkeypress", "return inspectEvent(event)")
    5.         End If
    6.     End Sub
    Last edited by wild_bill; May 3rd, 2005 at 01:04 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width