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 8123673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:15:07+00:00 2026-06-06T06:15:07+00:00

I’m fairly new to web development and I’d like to think I am getting

  • 0

I’m fairly new to web development and I’d like to think I am getting the hang of it, the only major problems I keep running into are cross-browser compatibility issues.

I have a textarea on a webpage that will call a function after the user is done typing. In order to do this, I am using jQuery and setTimeout to wait a bit before calling the function. This ensures that the function isn’t called after every single keypress. I don’t want it called after every keypress because the function sends a request to a servlet which does some processing and returns.

The code works fine on Chrome (I use Chrome for debugging it), but it doesn’t work with IE7. Here it is:

var timer = null;
$("#scriptInput").keypress(function() {
    clearTimeout(timer);
    var thisEvent = window.event;
    timer = setTimeout(function() {validateScript(thisEvent);}, 500);           
});


function validateScript(evt) {
  var code = (evt.keyCode) ? evt.keyCode : evt.which;

  //check which key was pressed...
  //don't need to send a request on key presses of CAPSLOCK, SHIFT, and ARROW keys
  if(code != 20 && code != 16 && code != 37 && code != 38 && code != 39 && code !=40){ 
    sendRequest(2);
  }
}

As you can see, I’ve already made numerous attempts at implementing compatibility with IE7, but to no avail :\

It must be compatible with at least IE7 because it will be used by a number of machines which use IE7 and don’t have the privileges to upgrade.

Let me know if you need anymore info!
Thanks!

P.S. “scriptInput” is the id of the textarea this is affecting.

  • 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-06T06:15:08+00:00Added an answer on June 6, 2026 at 6:15 am

    var thisEvent = window.event; is not cross-browser compatible – not all browsers use the global event object but a function argument instead.

    jQuery always provides you with an event object as a function argument, so simply remove the above assignment and change your code like this:

    $("#scriptInput").keypress(function(thisEvent) {
        ...
    });
    

    jQuery also normalizes the various properties for the pressed keys into e.which so you can get rid of var code = (evt.keyCode) ? evt.keyCode : evt.which; and simply use evt.which all the time.


    You can also improve/shorten the whole thing a bit more. If adding another library is fine I’d use _.debounce from Underscore.js to do the timing:

    $("#scriptInput").keypress(_.debounce(validateScript, 500));
    

    Instead of Underscore.js you could also use a jQuery plugin providing that functionality.

    If adding additional third-party code is not an option I’d store the timer on the element instead of a (possibly global) variable:

    $("#scriptInput").keypress(function(e) {
        var $this = $(this);
        window.clearTimeout($this.data('timer'));
        $this.data('timer', window.setTimeout(function() {
            validateScript(e)
        }, 500));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.