Pass selected value to function using jquery selector
javascript, jquery, menu, select
Solution
Jquery change method can be used here Change()
$(function()
{
$('#year_menu').change(function(){
select_year_data($(this).val())
});
});
Problem
I am a new jquery/js user trying to pass an argument from a selector to a function. Here is some of the code: ``` // function to select data var data = [ {val: 10, year: 1990}, {val: 20, year: 1991} ] var year_data = [] function select_year_data(y) { year_data = data.filter(function(d) {return d.year==y}) } ``` // Selector ``` <select name="Year" id = "year_menu" style="width: 230px; position: absolute; left: 400px; top: 50px"> <option value=1990>1990</option> <option value=1991>1991</option> </select> ``` What I would like to do is something like this: ``` <onchange>select_year_data($('#year_menu.val()') ``` But I know that isn't quite right.