Swaroop Komma Swaroop Komma - 5 months ago 27
HTML Question

if checkbox checked that time first select option selected

if checkbox

checked
that time first select option
selected
but below code works first time. when second time checked it will not working.

<input type="checkbox" class="ivrs02_yes">
<select class="destination_type_select3">
<option>slect</option>
<option>slect2</option>
<option>slect3</option>
</select>


$(document).ready(function() {
$(".ivrs02_yes").click( function(){
$('.destination_type_select3 option:first-child').attr("selected", "selected");
});
});

Prs Prs
Answer

Try this way..

$(".ivrs02_yes").change(function() {
    if ($(this).is(':checked')) {
       $('.destination_type_select3 option:eq(0)').prop('selected', true);
    }
});

$(document).ready(function() {
  $(".ivrs02_yes").change(function() {
    if ($(this).is(':checked')) {
      $('.destination_type_select3 option:eq(0)').prop('selected', true);
    }
  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" class="ivrs02_yes">
<select class="destination_type_select3">
  <option>slect</option>
  <option>slect2</option>
  <option>slect3</option>
</select>