【发布时间】:2014-04-07 15:18:04
【问题描述】:
我需要从我的控制器向特定方法提交表单。 我怎样才能做到这一点? 我的表单如下所示:
<%= form_tag({update_holidays_path, method: 'post'},{name: "exchange", id: "exchange"}) do %>
<table width="auto" border="0">
<thead>
<th scope="col">Selected</th>
<th width="50" scope="col"> </th>
<th scope="col">Holidays</th>
</thead>
<tbody>
<tr>
<td>
<% holidays_array = @group.holidays.all.map { |holiday| [holiday.name, holiday.id] } %>
<%= select(:holiday_id, :name, options_for_select(holidays_array),{},
{:multiple => true, :style => "width: 300px; background-color: #9FE", :width => "300", :size => 20, :id=>"left" } ) %>
</td>
<td align="center">
<%= link_to "<<", {anchor: "", remote: true}, {id: "toleft" , w_command: "add_holiday", w_auth: form_authenticity_token , w_controller: "groups", w_id: @group.id} %>
<br /><br />
<%= link_to ">>", {anchor: "", remote: true}, {id: "toright" , w_command: "rem_holiday", w_auth: form_authenticity_token , w_controller: "groups", w_id: @group.id} %>
</td>
<td>
<% holidays_array = Holiday.all.map { |holiday| [holiday.name, holiday.id] } %>
<%= select(:holiday_id, :name, options_for_select(holidays_array),{},
{ :multiple => true, :style => "width: 300px; background-color: #F99", :width => "300", :size => 20, :id=>"right" } ) %>
</td>
</tr>
</tbody>
</table>
我想使用以下 javascript 提交我的左侧选择:
var save=function()
{
alert("0");
var left = document.getElementById("left");
alert(left);
var result = document.exchange;
alert(result);
result= ""
alert("3");
for(i=0;i<right.length;i++)
{
result.value=result.value+","+left.options[i].value; //right.options[i].selected = true;
alert("4,"+i+" "+result.value);
}
alert("5");
result.submit();
}
有没有办法做到这一点?
【问题讨论】:
标签: javascript jquery ruby-on-rails forms