简体   繁体   中英

How to enable a second dropdownlist when a textbox has data and dropdownlist is selected?

I have a textbox #Email and I have two dropped down list menus that is #Carriers and #Phones. When the Email is entered I want to enable only Carriers drop box but not the Phones. When the Carriers is selected the Phones dropdownlist has to be enabled. The Phones dropdownlist can only be enabled when there is an email and carriers selected. If user enters email and selects an item from #carriers and #phones and then email is erased the two drop menus have to be disabled. Is there a way that I can do a compound sentence? Below is the working Carriers when email is entered.

          $(document).ready(function () { //Will check for e-mail and enable #Phones dropdownlist, otherwise, it will disable dropdownlist of #Phones
             $('#Email').on('input change', function () { //check to see if email textbox is empty
        if ($(this).val() == '') {
            $('#Phones').prop('disabled', true);
        }
        else {
            $('#Phones').prop('disabled', false);
        }
    });
});

Need this to included #Phones && #Carriers

    <script>
$(document).ready(function () {//need this to enable when email and carriers is selected. 
    $('#Email').on('input change', function () { //check to see if email is empty
          if ($(this).val() == '') {
            $('#Phones').prop('disabled', true);
          }
        else {
            $('#Phones').prop('disabled', false);
        }
    });
});

$('#Email').on('input change', function () { //check to see if email is empty
      if ($(this).val() == '') {
        $('#Carriers').prop('disabled', true);
        $('#Phones').prop('disabled', true);
      }
    else {
        $('#Carriers').prop('disabled', false);
    }
});

This will enable Carriers when you change Email but will disable both Carriers and Phones if you delete it.

$('#Carriers').change(function () { 
      if ($('#Carriers').val() == '') {
        $('#Phones').prop('disabled', true);
      }
    else {
        $('#Phones').prop('disabled', false);
    }
});

and this will enable Phones when you change Carriers. You are already checking E-mail at first action and disable Carriers if there is no value so you don't need to do this again here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM