Include Option/Select in search

Asked

Viewed 42 times

0

Good afternoon guys, I’d like to include the option for my research, I’ve tried it like this:

var $search = $("#search").on('input, option',function(){
        $btns.removeClass('active');
        var matcher = new RegExp($(this).val(), 'gi');
        $('.box').show().not(function(){
            return matcher.test($(this).find('.name, .sku, .local').text())
        }).hide();
    })

But I didn’t succeed.

  • 1

    For when you change it automatically search?

  • That’s right, the way I’m using it gets the result of a database option, but it appears for the user to select which one they want to be searched.

  • 1

    Try it this way: $("#search").on('change',function(){ //corpo })

  • You want to take the value of a select?

1 answer

-1

Change this line

var matcher = new RegExp($(this).val(), 'gi');

for

var matcher = new RegExp(this.value, 'gi');

and the line

var $search = $("#search").on('input, option',function(){

for

$('#search').on('change', function () {

Browser other questions tagged

You are not signed in. Login or sign up in order to post.