javascript - How to select default options from multiple select boxes using select2 -


in code there 3 different select box. when selectbox clicked, others receive default value 1 select box active.

<select class="form-control select2" style="width: 100%;" id="seleciona_combo">     <option value="a">select food</option>     <option>aba</option> </select>  <select disabled class="form-control select2" style="width: 100%;" id="seleciona_produto">     <option value="b">select drink</option> </select>  <select class="form-control select2" style="width: 100%;" id="seleciona_adicionais">     <option value="c">select add</option>     <option>oi</option> </select> 

javascript:

    $("#seleciona_combo").on("change", function(){         $("#seleciona_produto").select2().select2('val','b');         $("#seleciona_adicionais").select2().select2('val','c');     });      $("#seleciona_adicionais").on("change", function(){         $("#seleciona_combo").select2().select2('val','a');         $("#seleciona_adicionais").select2().select2('val','c');     });      $("#seleciona_adicionais").on("change", function(){         $("#seleciona_produto").select2().select2('val','b');         $("#seleciona_combo").select2().select2('val','a');     }); 

assuming mean 1st option "default" try this:

$('.form-control').on("change", function(){   var $var = $(this)   $('.form-control').each( function(){     if( $var != $(this) )        $(this).selectedindex = 0   }) 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -