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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:28:41+00:00 2026-05-11T22:28:41+00:00

In my form I have a set of input boxes where a user can

  • 0

In my form I have a set of input boxes where a user can input a value.
On change of one of these boxes, the form automatically gets submitted.

The problem now is however that a user stays in the last field, takes the mouse and presses the OK button (of another form) without leaving the textbox first. The change event doesn’t get triggered and the old, incorrect values get passed to the next page.

I want to trigger the onchange event after a few miliseconds of inactive keyboard. Just like most autocomplete plugins do.
I think I could implement a timer that starts timing the moment you enter an input field and gets resetted everytime a keystroke is handled and then when it reaches zero the onchange event gets triggered.

I’m not up for re-inventing the wheel and was wondering if such a function is available somewhere.
Suggestions?

  • 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-05-11T22:28:42+00:00Added an answer on May 11, 2026 at 10:28 pm

    I had a similar problem and created a jQuery plugin currently in use in an internal application. It should trigger the change event after the user is done typing.

    If you are not using jQuery, the code is still adaptable to anything else.

    jQuery.fn.handleKeyboardChange = function(nDelay)
    {
        // Utility function to test if a keyboard event should be ignored
        function shouldIgnore(event) 
        { 
            var mapIgnoredKeys = {
                 9:true, // Tab
                16:true, 17:true, 18:true, // Shift, Alt, Ctrl
                37:true, 38:true, 39:true, 40:true, // Arrows 
                91:true, 92:true, 93:true // Windows keys
            };
            return mapIgnoredKeys[event.which];
        }
    
        // Utility function to fire OUR change event if the value was actually changed
        function fireChange($element)
        {
            if( $element.val() != jQuery.data($element[0], "valueLast") )
            {
                jQuery.data($element[0], "valueLast", $element.val())
                $element.trigger("change");
            }
        }
    
        // The currently running timeout,
        // will be accessed with closures
        var timeout = 0;
    
        // Utility function to cancel a previously set timeout
        function clearPreviousTimeout()
        {
            if( timeout )
            { 
                clearTimeout(timeout);
            }
        }
    
        return this
        .keydown(function(event)
        {
            if( shouldIgnore(event) ) return;
            // User pressed a key, stop the timeout for now
            clearPreviousTimeout();
            return null; 
        })
        .keyup(function(event)
        {
            if( shouldIgnore(event) ) return;
            // Start a timeout to fire our event after some time of inactivity
            // Eventually cancel a previously running timeout
            clearPreviousTimeout();
            var $self = $(this);
            timeout = setTimeout(function(){ fireChange($self) }, nDelay);
        })
        .change(function()
        {
            // Fire a change
            // Use our function instead of just firing the event
            // Because we want to check if value really changed since
            // our previous event.
            // This is for when the browser fires the change event
            // though we already fired the event because of the timeout
            fireChange($(this));
        })
        ;
    }
    

    Usage:

    $("#my_input").handleKeyboardChange(300).change(function()
    {
        // value has changed!
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have radio boxes of the form <li><input type=radio name=names value=blah><a>Some text (blah)</a></li>
I have a form containing two text boxes for user input. Both text boxes
I have set up an AJAX contact form on a client's website. The problem
I have a form with sixteen combo-boxes, each with the DropDownStyle property set to
i have a form and a sortable() list where a user can drag from
I have a form I'm trying to set up ... Users can have many
I have a form with an input type=password and it gets consistently preloaded with
I have a form containing a list of input fields that the user populates
I have an input set to a type of image: <form id=MapForm action=#> <input
I have a quotation form where the user fills out the boxes, clicks submit

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.