I have some options in a select tag and a input text box. Once user enters something in text box the related options should be displayed rest needs to be hidden.
<select size="8" style="width:150;">
<option value="something1">Apple</option>
<option value="something1">Banana</option>
<option value="something2">Mango</option>
<option value="something2">Orange</option>
<option value="something2">Papaya</option>
<option value="something3">Grape</option>
<option value="something3">Coco</option>
<option value="something3">Chocolate</option>
</select>
<input type="text" >
When I enter ap
in text box, only Apple, Papaya should be visible.. Please let me know how I can achieve this by jQuery..
I have some options in a select tag and a input text box. Once user enters something in text box the related options should be displayed rest needs to be hidden.
<select size="8" style="width:150;">
<option value="something1">Apple</option>
<option value="something1">Banana</option>
<option value="something2">Mango</option>
<option value="something2">Orange</option>
<option value="something2">Papaya</option>
<option value="something3">Grape</option>
<option value="something3">Coco</option>
<option value="something3">Chocolate</option>
</select>
<input type="text" >
When I enter ap
in text box, only Apple, Papaya should be visible.. Please let me know how I can achieve this by jQuery..
2 Answers
Reset to default 5demo: https://so.lucafilosofi./narrow-down-the-select-options-from-text-search-using-jquery
$(function() {
$('input.search').on('change', function() {
$(this).prev('select.term').find('option:not(:containsi(' + this.value + '))').hide();
}).on('keyup', function() {
$(this).prev('select.term').find('option:containsi(' + this.value + ')').show().attr('selected', true);
}).extend($.expr[':'], {
'containsi' : function(elem, i, match, array) {
return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || '').toLowerCase()) >= 0;
}
});
});
i suggest you to search and look at this SO post:
Jquery: Filter dropdown list as you type
or this example URL
http://andrew.hedges.name/experiments/narrowing/