dimanche 27 décembre 2020

JQuery multiple identical section disable submit button on select menu option

I have multiple blocks such as:


In order to not allow submission if no option is selected in the select menu (text = 'Select', val = ''), I use JQuery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>
  $(document).ready(function(){
    $('#download_option').on("change",function(){
      if($(this).val() == ''){
        $('#download_submit').attr('disabled','disabled');
      }else{
        $('#download_submit').removeAttr('disabled');
      }
    });
  });
</script>

This code will work as expected: enabling the submit button if select option is different than the default.

However, it will work only for the first block. For all others, the button will remain disabled. So I would like a way to use a "parent" function or anything to make it working for all blocks accross the document.




Aucun commentaire:

Enregistrer un commentaire