I want to display the "config" dropdown if the checked count of "valve_type_array" checkbox is greater than zero. And append the checked checkbox values to the "config" dropdown. I'm stucked in appending the checked checkbox values to the dropdown. Any help would be greatly appreciated.
HTML:
<div id="type">
<input type="checkbox" name="valve_type_array[]" value="Test1"><span>Test1</span><br>
<input type="checkbox" name="valve_type_array[]" value="Test2"><span>Test2</span><br>
<input type="checkbox" name="valve_type_array[]" value="Test3"><span>Test3</span><br>
<input type="checkbox" name="valve_type_array[]" value="Test4"><span>Test4</span>
</div>
<select class="form-control hide" id="config" name="config">
<option value="">Please select</option>
</select>
jQuery:
$(document).ready(function(){
var $checkboxes = $('#type input[type="checkbox"]');
$checkboxes.change(function(){
var countCheckedCheckboxes = $checkboxes.filter(':checked').length;
if(countCheckedCheckboxes > 0){
$("#config").show();
}
});
});