javascript - How to change the selected text in a drop down list in rails application based on a variable? -
i have select drop down box list of currencies. make easier users, want change default selected value in drop down when page loads based on user country (will use geoip gem that) writing ruby code:
$country = geoip.geolocation(request.remote_ip, :precision => :country)
how change selected value of drop down list box based on $country value? should javascript? or rails forms helper?? , code it?
all need set <option>
element has country selected='selected'
. how depends on how built option list.
for example, options_for_select
takes selected element 2nd argument.
options_for_select(['alpha', 'beta', 'gamma'], 'beta') # => <option value="alpha">alpha</option> # => <option value="beta" selected="selected">beta</option> # => <option value="gamma">gamma</option>
Comments
Post a Comment