youssef hassoun
youssef hassoun

Reputation: 350

how use jquery to get selected value using simple form of ruby on rails

i have a problem to get the value of a selected value from a dropdownlist

my code jquery is : $( "#statistic_commune option:selected" ).text();

this code work when i use just html like : select.form-control name="statistic[state]" id="statistic_commune "

but it doesn't work when i use : rails tag like = towns_select_tag(:statistic, :commune, {include_blank: true}, {class: 'form-control'},{id: 'statistic_commune'}) help please

Upvotes: 0

Views: 2264

Answers (2)

Mayur Shah
Mayur Shah

Reputation: 3449

You should do like this

= towns_select_tag(:statistic, :commune, {include_blank: true}, {class: 'form-control'}, :id => "statistic_commune")

You should get value by using:

$('#statistic_commune').val();

Upvotes: 2

Snake
Snake

Reputation: 1197

You need to target the select tag :

$( "#statistic_commune" ).val();

Upvotes: 1

Related Questions