Ruby on rails with JQuery passing from div to div

In one html page I have the first div

<div>
    <select class="margin-bottom-20" id="event_title" name="event_title" style="width: 150px;">
        <option value="" selected><%= "Select a Title"%></option>            
        <% @all_events_title.each do |t| %>
            <option value="<%= t %>"><%= t %></option> 
        <% end %>             
    </select>
</div>

      

Second div,

<div>
    @events_all.each do |e|
        if e["title"] == **document.getElementById("event_title").value;**
            @all_events_by_title << e
        end 
    end
    <span><%=e["sport"]%></span>
</div>

      

how can i get the value event_title

for the second div dynamically?

Thanks in advance!

+3


source to share


1 answer


Create a script tag in the same html to add a div with javascript



<script type="text/javascript">
  $(function () {
    var $divEl = $("<div>");
    var eventTitle = document.getElementById("event_title").value;
    <% @events_all.each do |e| %>
      var title = <%= e["title"] %>;
      if (eventTitle = title) {
        // not sure what you are trying to do here...
        <% @all_events_by_title << e %>
      }
      var $spanEl = $("<span>").html(<%= e["sport"] %>);
      $divEl.append($spanEl);
    <% end %>
    $("body").append($divEl);
  });
</script>

      

0


source







All Articles