asp.net - Javascript & Listbox Item Removal -
i've got simple aspx page listbox, textbox , button. listbox loaded @ page_load event 40 or items.
the button fires off following javascript, supposed remove listbox item not contain value typed user in textbox. basically, it's supposed search tool.
problem is, removes half of items should. have click button 4 times results should have gotten on first click. here's function:
function search() { var strsearch = document.getelementbyid("<%= txtsearch.clientid %>").value; var lstrsns = document.getelementbyid("<%= lstreasons.clientid %>"); var temp; var i; for(i=0;i<lstrsns.options.length;i++) { temp = lstrsns.options[i].text.touppercase(); if (temp.indexof(strsearch.touppercase()) == -1) { lstrsns.remove(i); } } }
what doing wrong? seems should work.
thanks any/all advice,
jason
the list keeps shortening remove elements.. lstrsns.remove(0);
in loop until hit 1 you're looking , after lstrsns.remove(1);
.
Comments
Post a Comment