Skip to content
Advertisement

Refresh selectpicker options after jQuery success is not working

I am trying to refresh a select after executing another jQuery. I am creating firstly the select options using cURL, which produces code like this.

JavaScript

Then I have the HTML that looks like htis

JavaScript

I am loading the options into the select with this jquery

JavaScript

Which works fine. Then I have another script to delete an option from the select using ajax

JavaScript

In this script, what I am trying to achieve is to refresh the options after the delete script is successful, using the same script I am using to initially create the options. It seems I am doing something wrong, but I cannot figure out what.

UPDATE

Just realized that if I remove the selectpicker and try to remove the option that I just deleted from the select in the success like this $("#topic_del option[value='" +topic+ "']").remove(); it will work. However, if I put back the selectpicker it will not remove the option. Could it be something with the selectpicker not allowing to do it?

Advertisement

Answer

I was able to achieve the functionality thanks to this thread Selectpicker with add or delete values

by adding these two lines in the success

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement