Rajesh Gowda Rajesh Gowda - 3 months ago 5x
jQuery Question

Retrieve the value of the select option in a View

I have the following in my view:

<%= select_tag(:option_id, options_for_select([
['Students', 1],
['Teachers', 2],
])) %>

How do I retrieve the selected value in my View itself? I want to dynamically change the value of a
<%= link_to %>
based on it.

Here's my partial coffee script:

jQuery ->
$('#import_type').change ->

How do I now change the value of a
<%= link_to %>


You can do something like:

jQuery ->
  $('#import_type').change ->
    if $('#import_type').val() == '1'
      $('#link_to_id').attr("attribute", "value")

Make sure you replace link_to_id with the actual id.