[英]how to assign values to the input elements using getElementByTagName?
[英]how to assign input values to ruby varible?
我需要data-toggle =“ modal”中的選定值。 我正在獲取值,但無法分配給ruby變量,因此無法獲取所需的數據。
<%= form_for(:repair, :url => { :controller => "owners", :action => 'property_repairs',:owner_id => current_user.owner.slug }) do |f| %>
<%= collection_select(:property,:id,Property.where(owner_id: @owner.id, property_active: true).order(created_at: :desc),:id,:property_address,{:prompt => 'please select the property for Repair'},{class: "form-control"}) %>
<%= f.submit 'Repair', :class => 'btn btn-primary' %>
<% @repair = Repair.where(:owner_id => @owner.id)%>
<%end%>
<% @repair = Repair.where(:owner_id => @owner.id)%>
<% @repair.each do |repair| %>
<%property = Property.find(repair.property_id)%>
<tr>
<td class="input-group-addon "> <%=property.property_address %></td>
<td class="input-group-addon"> <%= repair.category %></td>
<td class="input-group-addon"> <%= repair.start_date %></td>
<td class="input-group-addon"> <%= repair.end_date%></td>
<td class="input-group-addon"> <%= repair.cost %></td>
<div id="pop">
<td button type="button" data-id = "<%=repair.id%>" class="input-group-addon" data-toggle="modal" data-target="#myPop">
<h class="text-primary text-left">View</h>
</td>
</tr>
<%end%>
我在同一個html.erb中給出了“模態”。 在這里,我要選擇的數據
<div class="modal fade" id="myPop" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<div class="modal-body">
<div>
<input id = "myPop" value ="">
</div>
</div>
</div>
</div>
在腳本內部,我獲得了價值,但無法在模態中分配,因為它是輸入價值
<script>
$(document).on("click", ".input-group-addon", function () {
var myBookId = $(this).data('id');
var value = $(".modal-body #myPop").val( myBookId );
});
</script>
提前致謝
如果要將該值存儲在數據庫中,則應使用AJAX調用ruby方法。 否則,您將無法將javascript-var分配給ruby-var。
使用:remote => true選項查看link_to或form_for:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.