简体   繁体   中英

Why jQuery Select box change event is not working?

I am working on product filters where user select from the select box according to his/her preference but I am not getting selected value by user in jQuery.

html code:

<select name="product_filter" id="product_filter">
        <option value="price_low_first">Price : Low to High</option>
        <option value="price_high_first">Price : High to Low</option>
        <option value="latest">Latest</option>
        <option value="popular">Most Popular</option>
</select>

jQuery code:

$(function () {
        $("#product_filter").change(function () {
          alert("hi")
            var selectedText = $(this).find("option:selected").text();
            var selectedValue = $(this).val();
            alert("Selected Text: " + selectedText + " Value: " + selectedValue);
        });
    });

Hi I believe that your code is perfect. Once please check jquery.min.js is included in your file. Please check if there are any console errors.Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM