How do i append values inside dropdownbox using jquery?
here is my html
<div class="input-field col s6">
<select id="graph_program" class="Programs">
</select>
<label>Program</label>
</div>
here is my script
$('#graph_college').on('change',function(){
var college = $('#graph_college option:selected').text();
$.ajax({
type:"POST",
url:"<?php echo base_url('administrator/getCourses')?>",
data:{college:college},
dataType:'json',
success : function(data){
console.log(data);
$(data).each(function(){
$('.Programs').append($('<option class="black-text"></option>').text(this.course_abbv));
});
}
});
});
and here is the result: (items are on the bottom side of the dropdown box)
ent$('#graph_college').on('change',function(){
var college = $('#graph_college option:selected').text();
$.ajax({
type:"POST",
url:"<?php echo base_url('administrator/getCourses')?>",
data:{college:college},
dataType:'json',
success : function(data){
console.log(data);
$(data).each(function(){
$('.Programs').append($('<option class="black-text"></option>').text(this.course_abbv));
});
$('select').material_select(); // answer
}
});
});
i needed to reinitialize the dropdownbox of materialize
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.