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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:35:43+00:00 2026-06-18T05:35:43+00:00

im sorry for this question but how can i disable a textbox if another

  • 0

im sorry for this question but how can i disable a textbox if another textbox have a value??
I already try this code but its not working,, sorry for the noob question T_T

function disable(downpayment,full_payment)
{

if ( downpayment.value.length >= 1 )
document.getElementById(full_payment).disabled = true;

else

document.getElementById(full_payment).disabled = false;
}



</script>
        <input name="downpayment" id="downpayment" type="text" onselect="function disable(downpayment,full_payment);" style="width:250px" />
      </p>
      <p>
        <input name="full_payment" id="full_payment" type="text" style="width:250px" />
  • 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-18T05:35:45+00:00Added an answer on June 18, 2026 at 5:35 am

    If you want to stay with plain JavaScript:

    // finding the relevant elements *outside* the function
    var downpayment = document.getElementById('downpayment'),
        full_payment = document.getElementById('full_payment');
    
    function enableToggle(current, other) {
        /* 'current' is the element that currently has focus
           'other' is the other input element, that does not have focus.
    
        1. if the 'current' value of the focused/active element, once the whitespace
           is removed, is greater than 0 (so it has something in it other than whitespace,
           the disabled property of the 'other' element is true,
        2. if the 'current' element has only whitespace, and/or a zero-length value,
           the 'other' element's disabled property is false.
        */
    
        other.disabled = current.value.replace(/\s+/,'').length > 0;
    }
    
    // using the onkeyup event to call a function on the elements.
    downpayment.onkeyup = function () {
        enableToggle(this, full_payment);
    }
    full_payment.onkeyup = function () {
        enableToggle(this, downpayment);
    }
    

    This works with the following HTML:

    <input name="downpayment" id="downpayment" type="text" style="width:250px" />
    <input name="full_payment" id="full_payment" type="text" style="width:250px" />
    

    JS Fiddle demo.

    If you’re using jQuery already, then you can either nest the above into jQuery’s $(document).ready(function(){ /* the code in here */});, or switch to a jQuery-only solution, such as Alex’s.

    To stick with plain-JavaScript, and avoiding explaining how to set up an equivalent DOM-ready event, put the following at the end of your HTML content, just before the closing </body> tag:

    <script>
        var downpayment = document.getElementById('downpayment'),
            full_payment = document.getElementById('full_payment');
    
        function enableToggle(current, other) {
            other.disabled = current.value.replace(/\s+/,'').length > 0;
        }
    
        downpayment.onkeyup = function () {
            enableToggle(this, full_payment);
        }
        full_payment.onkeyup = function () {
            enableToggle(this, downpayment);
        }
    </script>
    

    (This is exactly the same JavaScript as above, with the comments stripped out, but wrapped in <script></script> tags)

    Putting this at the bottom of the HTML means that the elements exist in the DOM prior to your trying to assign event-handlers to them.

    Incidentally, with adjusted HTML, to give:

    <form>
    <!--
         I associated the relevant elements with a class-name 'enableToggle',
         you don't have to, it just reduces the work the jQuery has to do later
         when using siblings('.enableToggle') to find the relevant elements.
    -->
    <div>
        <label for="downpayment">Downpayment</label>
        <input name="downpayment" class="enableToggle" id="downpayment" type="text" style="width:250px" />
        <label for="full_payment">Full payment</label>
        <input name="full_payment" class="enableToggle" id="full_payment" type="text" style="width:250px" />
    </div>
    </form>
    

    The following jQuery could be used:

    // binds both event-handler to both 'keyup' and 'paste' events.
    $('.enableToggle').on('keyup paste', function(){
        /* 'curVal' is a Boolean (true or false) depending on whether there's
            a value other than whitespace */
        var curVal = $(this).val().replace(/\s+/g,'').length > 0;
    
        /* sets the 'disabled' property of the sibling elements of the current
           element, as long as those siblings have the class 'enableToggle'
           (this avoids having to explicitly identify all the elements you want
           to act on). */
        $(this).siblings('.enableToggle').prop('disabled', curVal);
    });
    

    JS Fiddle demo.

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

Sidebar

Related Questions

I'm sorry if this question has been asked. I have looked but can not
Sorry if this question has already been answered but I can't find an answer.
Sorry this is going to sound like a ridiculous question but can methods (not
sorry this is such a simple question but I can't figure it out. How
Sorry if this question is very easy, but I can't find the answer anywhere.
Sorry for this simple question, but I can't solve it... There is an example:
Sorry for this newbie question, but I can't find on google what I need
I'm sorry to ask this question but I have spent hours trying to understand
Sorry but I am not sure how to ask this question but I am
Sorry if this question seems a bit complex but I think its all related

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.