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

  • Home
  • SEARCH
  • 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 6351655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:02:54+00:00 2026-05-24T22:02:54+00:00

I have an input element and I want to keep checking the length of

  • 0

I have an input element and I want to keep checking the length of the contents and whenever the length becomes equal to a particular size, I want to enable the submit button, but I am facing a problem with the onchange event of Javascript as the event fires only when the input element goes out of scope and not when the contents change.

<input type="text" id="name" onchange="checkLength(this.value)" />

—-onchange does not fire on changing contents of name, but only fires when name goes out of focus.

Is there something I can do to make this event work on content change? or some other event I can use for this?
I found a workaround by using the onkeyup function, but that does not fire when we select some content from the auto completer of the browser.

I want something which can work when the content of the field change whether by keyboard or by mouse… any ideas?

  • 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-24T22:02:54+00:00Added an answer on May 24, 2026 at 10:02 pm
    (function () {
        var oldVal;
    
        $('#name').on('change textInput input', function () {
            var val = this.value;
            if (val !== oldVal) {
                oldVal = val;
                checkLength(val);
            }
        });
    }());
    

    This will catch change, keystrokes, paste, textInput, input (when available). And not fire more than necessary.

    http://jsfiddle.net/katspaugh/xqeDj/


    References:

    textInput — a W3C DOM Level 3 event type. http://www.w3.org/TR/DOM-Level-3-Events/#events-textevents

    A user agent must dispatch this event when one or more characters have
    been entered. These characters may originate from a variety of
    sources, e.g., characters resulting from a key being pressed or
    released on a keyboard device, from the processing of an input method
    editor, or resulting from a voice command. Where a “paste” operation
    generates a simple sequence of characters, i.e., a text passage
    without any structure or style information, this event type should be
    generated as well.

    input — an HTML5 event type.

    Fired at controls when the user changes the value

    Firefox, Chrome, IE9 and other modern browsers support it.

    This event occurs immediately after modification, unlike the onchange event, which occurs when the element loses focus.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an input element, and i want bind both change and keypress event
I have an INPUT element of the TEXT type and I want to perform
I have an input type=file element with size=70 and width=522px . It looks and
I have a form with an input element but no submit button. I use
I have an form input element and want to change its title attribute. This
I have a form called wizard. Everytime any input element is changed, I want
I have a input element: <input type=text id=t value=abcdefghij /> I want to create
I have a file input element which generate by ajax/jquery.load(). and when I want
I have an input element like: <input class=input-m name=formelement[] type=text> I want to clone
I have INPUT element and I want to reset the previous value (not necessary

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.