Reputation: 622
I am working on a rails application in which I would like to have active links in each option of my select box that point to the show pages for each respective venue
<select class="form-control" id="exampleSelect1">
<% @venus.each do |ven|%>
<option><%= link_to ven.name, venue_path(ven.id) %></option>
<% end %>
</select>
</div>
I am sure that there is nothing wrong with the link itself, but when i click on an option on my webpage, nothing happens. I have tested it using dummy links ie
<option onClick="window.location = 'http://www.google.com'">A</option>
and
<option value ='http://www.google.com'>A</option>
Everything shows up in my select box but none of the links work. Nothing happens when I click them.
Upvotes: 1
Views: 216
Reputation: 3018
Use the onChange
property instead of onClick
.
<select class="form-control" id="exampleSelect1" onChange="window.location.href=this.value">
<% @venus.each do |ven|%>
<option><%= link_to ven.name, venue_path(ven.id) %></option>
<% end %>
</select>
Upvotes: 1