Remove all dropdown list items except selected using jQuery
So this example I can divided in to two parts.
1. When the drop-down list value already set from the back end.
2. Remove drop-down option when user change the drop down list values.
When the drop-down list value already set from the back end.
That means the drop-down data already defined from the back end and we need to display the drop-down list data according to the data came from the back end.
For example, If there are several locations available in the system and according to the login user location we need to customize the drop down list for the user.
If the user location is "Matara" we need to remove all other locations from drop-down and display "Matara" to user as the location.
Here I unable to set the drop-down value from back end, so I have to set the value in document ready function using jQuery.
So it remove the values other than selected.
Remove drop-down option when user change the drop down list values.
When the time user change the drop down, It only remain the selected option and other options are removed.
Now we have drop-down list with Fruits(Grapes, Bananas, Oranges and Apples).
So we need to remove the options other than selected option.
For example, If user select Apples, then drop-down list only contains Apples, other options should be removed.
Output displays Select Fruit and Apple
If you want to remove Select fruit option also, You can remove :eq(0) from onChange function.