Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8323937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:52:46+00:00 2026-06-08T23:52:46+00:00

Currently I am trying to force uppercase in a textbox in a javascript method.

  • 0

Currently I am trying to force uppercase in a textbox in a javascript method. This method is set to be called on a ‘keypress’ event to go into a textbox.

Here is my method to change to uppercase with IE and FF detection.

          //some code to detect the kind of key pressed based on numeric value, 
          //if lowercase detected then continue

        var key; 
        if(window.event){ //working IE code                     
                //key = window.event.keyCode;
                window.event.keyCode-=32;
        }

        else if(e){ //broken FF code
                key = String.fromCharCode(keycode).toUpperCase()
                e.value = e.value.toUpperCase();
        }

This current code says e.value is undefined in firebug. If i try just e.toUpperCase() firebug says toUpperCase does not exist. I have tried setting e.value equal to ‘key’, which returns no errors but does not change to uppercase. I have tried directly changing e.which but of course, that is read only and returns an error saying such.

What exactly am I missing here? I believe that the problem is no matter what I change here, e.which is STILL set as the lowercase value, and because I can’t edit it in any way, the original lowercase e.which character is getting pushed to the textbox.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:52:47+00:00Added an answer on June 8, 2026 at 11:52 pm

    I think I would do this another way:

    function keypressHandler() {
      this.value = this.value.toUpperCase();
    }
    
    document.getElementById('whatever').onkeypress = keypressHandler;
    // or use addEventListener or whatever
    

    edit actually it works a little better with the following hack:

    function keypressHandler(event) {
        var inp = this;
        setTimeout(function() {
            inp.value = inp.value.toUpperCase();
        }, 0);
    }
    

    That lets the key that caused the event get added to the value before the value is “fixed”.

    The point is that handling keyboard events is pretty messy and things vary between browsers. The approach above avoids that entirely by simply working directly on the value, which is maintained by the browser.

    edit — note that for the code here to work, the event handler has to be set up the way this code does it. If you set it in the “onkeypress” attribute in the HTML markup, it’d have to be different:

    <input onkeypress='keypressHandler.call(this)'>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to set up a secured folder with a few pages within
I'm currently trying this: using DocumentFormat.OpenXml.Packaging; using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileNameDocx as string, true))
I'm currently trying to get the most popular productID from my MSSQL Database. This
I am currently trying to implement a jquery slider into a joomla website. I
I am currently trying to implement DropBox into my Android App. I have added
I am currently trying to add a a settings into my application but I
Using JAVA, I'm trying to force the browser to download files. Here is the
Currently trying at add ajax to a site, after much reading I discovered that
Im currently trying to downlaod a audio track from a WCF, i need some
Im currently trying to learn some stuff about encryption, it's algorithms and how it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.