SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Evangelist anjanesh's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onkeypress change key to uppercase

    Hi

    On hitting a key in a textbox I want it converted to UpperCase.
    Code JavaScript:
            document.getElementById("txt1").onkeypress = function(e)
             {
                    var e = e || window.event;
                    var k = e.which || e.keyCode;
                    k = String.fromCharCode(k).toUpperCase().charCodeAt(0);
     
             }
    This obviously doesnt work because the function is called after the key is pressed and k doest reference the key in the textbox.

    Is there a way ?
    Thanks
    Anjanesh

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.getElementById("txt1").onkeyup = function(){
    document.getElementById("txt1").value=
    document.getElementById("txt1").value.toUpperCase();
    }


Bookmarks

Posting Permissions

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