This question already has an answer here:
I have a search box that limits options available in a dropdown menu on keyup. I'm having an issue with case sensitivity - how can I modify this function to ensure my option
contains upper or lower case versions of the character typed?
Fiddle: https://jsfiddle.net/g2q8hvf4/
Notice how the results differ between 'i' and 'I'
$(document).on('keyup', '#condition-search', function(e) {
var str = $('#condition option:contains(' + $(this).val() + ')');
if (str) {
$('#condition option').hide();
str.show();
} else {
$('#condition option').show();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="form-control" id="condition-search">
<select class="form-control" id="condition" size="15" style="overflow-y: scroll" ;>
<option class="cat-1">Item1</option>
<option class="cat-2">item2</option>
<option class="cat-3">Item3</option>
<option class="cat-4">item4</option>
<option class="cat-5">Item5</option>
</select>
You can use the filter()
method and convert both the query and the current text to lower case before comparing:
$(document).on('keyup', '#condition-search', function(e) {
var query = $(this).val().toLowerCase();
var str = $('#condition option').filter(function () {
return $(this).text().toLowerCase().includes(query);
});
if (str) {
$('#condition option').hide();
str.show();
} else {
$('#condition option').show();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="form-control" id="condition-search">
<select class="form-control" id="condition" size="15" style="overflow-y: scroll" ;>
<option class="cat-1">Item1</option>
<option class="cat-2">item2</option>
<option class="cat-3">Item3</option>
<option class="cat-4">item4</option>
<option class="cat-5">Item5</option>
</select>
I'd compare the entered string in its lowercase version (using javascript's toLowercase()
) to your available list item's lowercase versions.
I'm not able to pass the state value to the method or function in React [closed]
How to access array index of Cloud Firestore using query in Flutter?
Getting an unwanted space between Nav Items in Navbar Angular
PHP Script INSERT INTO SELECT does not insert, with no errors [closed]
SQL query to select students who have taken all subjects from subjects table
Displaying Dynamic placeholder content on Textbox in ReactJS
Extracting Parameters from Redirect URI - QuickBooks API / Python
I have a Wordpress page with a text widget containing a select dropdown menu, along with a JQuery function to scroll to an id of a dl element in a separate content widget on the same pageThe dl elements are contained within separate columns on a different...
I have a function the parameter has more than one values which I'm passing them after a loopI want to use the values Im getting to replace integers in a string by there older
I have a Menu-list, and when I pass the mouse hover an item display another list, but this list is larger and change the height of the documentThis create a bug in the page
I am creating a horizontal scroller that you can click to scroll through images and everything scrolls fine, but I am not sure how I get the scroller to stop at the last pictureWhat I was trying to do was stop it at a certain pixel width but that is inconsistent