populating checkboxes based on dropdown value selection

倖福魔咒の 提交于 2019-12-12 02:28:23

问题


I was wondering if there is possibility to change the status of a checkbox to checked, based on a dropdown value selector.

I already managed to populate checkboxes based on radio button selection, but how would one do it for a dropdown list?

Dropdown is here:

 <select class="form-dropdown" style="width:150px" id="input_12" name="q12_broj_sati_dropdown">
        <option value=""> Odaberite broj sati </option>
        <option calcValue="240" value="4h" id="4h"> 4h </option>
        <option calcValue="300" value="5h" id="5h"> 5h </option>
        <option calcValue="360" value="6h" id="6h"> 6h </option>
        <option calcValue="420" value="7h" id="7h"> 7h </option>
        <option calcValue="480" value="8h" id="8h"> 8h </option>
        <option calcValue="540" value="9h" id="9h"> 9h </option>
        <option calcValue="600" value="10h" id="10h"> 10h </option>
        <option calcValue="660" value="11h" id="11h"> 11h </option>
        <option calcValue="720" value="12h" id="12h"> 12h </option>
      </select>

The checkboxes are on the right (Paypal checkboxes) here: http://kucanskiposlovi.com/narucite-dolazak/

I managed to populate checkboxes based on radio button selection with this code:

jQuery(document).ready(function() {
function subscribe() {
jQuery('input[type="radio"]').click(function() {
  var trimj = document.getElementById("input_52_0");
  var sestmj = document.getElementById("input_52_1");
  if (trimj.checked == true) {
    //check 3 mjeseca box, uncheck all other boxes
    jQuery("#input_63_1021").attr("checked", false); 
    jQuery("#input_63_1020").trigger('click');
  } else if (sestmj.checked == true) {
    //check 3 mjeseca box
    jQuery("#input_63_1020").attr("checked", false);  
    jQuery("#input_63_1021").trigger('click');
  }
});
}
subscribe();
});

回答1:


$('#select-box').on('change', function() {
  if($(this).val()=='something'){
    $('#your-check-box').prop('checked', true);
  }else{
    $('#your-check-box').prop('checked', false);
  }
});


来源:https://stackoverflow.com/questions/37098506/populating-checkboxes-based-on-dropdown-value-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!