javascript - jquery selectbox remove all options except two (selector variable name) -


i have following select box

<select name="loc_id_1" id="loc_id_1"> <option value="pls" selected="selected">-- please select --</option> <option value="new">-- add new --</option> <option value="1">smith company</option> <option value="6">jones company</option> <option value="23">wright company</option> </select> 

there multiple of these on page loc_id_2, loc_id_3, etc different info. using following detect change in of them.

$("[id^=loc_id_]").change(function(){ /// magic code var lc_id = $(this).attr('id'); my_function(lc_id,data1,data2); }); 

this part works great. problem running part of code, call function can refresh data in changed select box. use jquery remove function refresh selectbox

function my_function(id,d,f) { var sel = $("#" + id); sel.find('option[value!="new"] option[value!="pls"]').remove();  // ajax code calls database append other entries selectbox } 

the problem is, removes "add new" option, leaves "please select" options database added fine.

any idea how fix this...

your selector descendant inside option element having value new.try,

sel.find('option[value!="new"][value!="pls"]').remove(); 

demo


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -