Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  100] [ 6]  / answers: 1 / hits: 49040  / 10 Years ago, thu, april 24, 2014, 12:00:00

I used silviomoreto's bootstrap-select but I'm having problems.
I have 2 Dropdowns (Select) a Region dropdown and Cities. Now, I have a jquery onchange function, the function will change the values in the cities dropdown depending on the region selected. Here's my code:



<select id=region class=selectpicker></select>
<select id=cities class=selectpicker></select>

$(#region).on('change', function () {
$(#cities).html('<option>city1</option><option>city2</option>');
});


The problem is I think the compatibility? When I removed the class=selectpicker it works fine, but I can't remove it because I used it for my dropdown ui. I checked the documentation in here https://developer.snapappointments.com/bootstrap-select/ but I can't find relevant answer to my question. Thanks!


More From » jquery

 Answers
9

Try selectpicker('refresh').



refresh()




To programmatically update a select with JavaScript, first manipulate
the select, then use the refresh method to update the UI to match the
new state. This is necessary when removing or adding options, or when
disabling/enabling a select via JavaScript.




Snippet



$(#cities)
.html('<option>city1</option><option>city2</option>')
.selectpicker('refresh');


Working Demo: http://jsfiddle.net/codeandcloud/nr54vx7b/


[#71326] Tuesday, April 22, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
larrycodys

Total Points: 394
Total Questions: 93
Total Answers: 78

Location: Romania
Member since Mon, Jun 6, 2022
2 Years ago
;