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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:12:26+00:00 2026-06-16T19:12:26+00:00

I have a disabled element which I enable it only after value was entered

  • 0

I have a disabled element which I enable it only after value was entered to it’s previous input, the problem is that change triggers before the input lost focus and the focus moved to the next not disabled element, so removing the disabled attribute then is no good.

HTML:

Fill this before you continue:      <input id="a" />
Fill this after the previous input: <input id="b" disabled="disabled" />​

jQuery:

$('#a').change(function(){
    if (this.value === "")
        $('#b').attr('disabled', 'disabled');
    else
        $('#b').removeAttr('disabled');
});​

Fiddle

I manged to overcome this problem by changing from disabled to readonly but then it’s readonly and not disabled as I preferred, are there good and robust(mouse proof) ways to achieve it and using readonly?

Things to consider:

  • Subscribing to multiple events doesn’t really seems right.
  • The user can paste text to the 1st input without using keyboard at all.
  • 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-16T19:12:27+00:00Added an answer on June 16, 2026 at 7:12 pm

    You have said in your question that you don’t want to subscribe to multiple events, but this is the only way I can think of to do this. The problem is that different ways of changing the value of the input all interface directly with the C/C++ DOM, but they do not do it through the JS API. See this question for more on this.

    A reasonably bulletproof way of doing it while subscribing to multiple events would be:

    $('#a').on('keyup paste propertychange input', function() {
        if (this.value === "") $('#b').prop('disabled', true);
        else $('#b').removeAttr('disabled');
    });
    

    Here is a demonstration: http://jsfiddle.net/HmzYR/

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

Sidebar

Related Questions

I have a disabled input element that I am styling using the following CSS:
If have an element that maybe disabled on a page, and would like to
I have 2 input boxes that are not disabled. When either gets focus no
On a Jsp page I have some select elements which were disabled after a
i have disabled all the checkboxes except one. On click of that checkbox i
I have a set of checkboxes and have disabled few which I want to
I have a GUI which has a couple of checkboxes that control special modes
I have the following code which allows me to swipe an element, and the
We have a form with five <input type=file/> elements that is in production and
I have a simple function which disables/enables select element when checkbox is checked/unchecked. 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.