Skip to content Skip to sidebar Skip to footer

Disable Button From Option Select

Hello i want to disable button when a select option is a specific attribute. My code is this: If option value is Dove Sei? i want disable the button. I can try this code but don't

Solution 1:

  1. Your $("company") selector does not match anything, if you want to select by id, you should have used $("#company").
  2. Instead of $(this).find(':value').text(), please check: How do I get the text value of a selected option? - Since you also set the value property, you could simply use $(this).val()
  3. You have two buttons with the same id, keep in mind that the $("#buttonSurvey") selector in your action handler will always and only select the first one.

Solution 2:

  $(function() {
    $("#company").on('change', function(){
    if($(this).val()=="Dove Sei?")
      $("#buttonSurvey").attr('disabled',true)
    else
      $("#buttonSurvey").attr('disabled',false)
    });
  });

If you want to disable all buttons, you need use class in the selector:

$(".btn-default").attr('disabled',true)

Post a Comment for "Disable Button From Option Select"