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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:13:03+00:00 2026-05-11T04:13:03+00:00

How does one go about attaching a bunch of code to an onkeydown event,

  • 0

How does one go about attaching a bunch of code to an onkeydown event, but keep entering text into a textarea fast and crisp? Anything more than a couple of IF statements seems to slow it down quite considerably.

EDIT: I should add (can’t believe I forgot!) that this doesn’t affect desktop browsers. It’s mainly an issue with iPhone Safari. Other mobile browsers might be affected as well, but we’re focusing on iPhone Safari since it executes JS the best (AFAIK)

  • 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. 2026-05-11T04:13:04+00:00Added an answer on May 11, 2026 at 4:13 am

    Considering your edit regarding this being focused on iPhone access…

    The iPhone really just doesn’t have that much power to it. You’ll be better off just using onchange or onblur instead of onkeydown.



    An alternative to Dave’s answer is waiting for the user to pause (e.g. for 5 seconds):

    var textarea = document.getElementById('textarea');  function checkTextArea() {    if (textarea.value /* ... */) {      /* ... */    } }  textarea.keyDownTimeout = null; textarea.onkeydown = function () {   if (textarea.keyDownTimeout) clearTimeout(textarea.keyDownTimeout);   textarea.keyDownTimeout = setTimeout(checkTextArea, 5000); }; 

    This should set the timer with the first keydown, stopping and recreating the timer for each successive keydown. Finally calling 5 seconds after the user stops typing.

    Also, note the lack of parenthesis after checkTextArea. This will give setTimeout the function’s reference vs. its return.


    You can also set this up in a function to make it easier to use for multiple elements:

    function setPauseTimer(element, timeout, callback) {   var timer = null;   element.onkeydown = function () {     if (timer) clearTimeout(timer);     timer = setTimeout(function(){ callback(element); }, timeout);   }; }  function checkTextArea(textarea) { /* moved from global to argument */    if (textarea.value /* ... */) {      /* ... */    } }  setPauseTimer(document.getElementById('textarea'), 5000, checkTextArea); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perhaps I am missing something but how does one go about retrieving the xml
How does one go about catching exceptions from using controls in markup? For example,
How does one go about properly analyzing the requirements of a client in terms
I was curious as to how does one go about finding undocumented APIs in
In jQuery, how does one go about finding all the 'unchecked' checked boxes. $(':checkbox:checked');
Does any one know about opensource network monitor tool for BlackBerry ?
i am getting this error does some one knows about it??? 2009-07-08 18:42:36.778 FlashCards[1297:20b]
How does one go about adding JButton s among various other Swing GUI components
how does one go about accessing a decorator from a base class in a
How does one go about renaming an XML element using REXML or another Ruby

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.