【发布时间】:2015-07-23 19:47:46
【问题描述】:
我正在尝试在提交表单之前将表单中两个选择字段的值组合成一个变量。
这是我的代码:
在 new.html.erb(用于 RoR)中:
<%= form_for :character, url: characters_path, method: :post do |f| %>
<p>
<%= f.label :alignment %><br>
<%= f.select :alignment_lr, options_for_select([" ","Chaotic","Neutral","Lawful"], disabled: " ", selected: " ") %>
<%= f.select :alignment_ud, options_for_select([" ","Good","Neutral","Evil"], disabled: " ", selected: " ") %>
</p>
<% end %>
这会生成以下 html:
<p>
<label for="character_alignment">Alignment</label><br>
<select id="character_alignment_lr" name="character[alignment_lr]">
<option disabled="disabled" selected="selected" value=" "> </option>
<option value="Chaotic">Chaotic</option>
<option value="Neutral">Neutral</option>
<option value="Lawful">Lawful</option></select>
<select id="character_alignment_ud" name="character[alignment_ud]">
<option disabled="disabled" selected="selected" value=" "> </option>
<option value="Good">Good</option>
<option value="Neutral">Neutral</option>
<option value="Evil">Evil</option></select>
</p>
如何组合为:alignment_lr 和:alignment_ud 选择的值以等于alignment.value = alignment_lr.value + ' ' + alignment_ud.value 之类的值?
我愿意使用 javascript 或 jquery 来解决这个问题。
【问题讨论】:
标签: javascript jquery html ruby-on-rails ruby-on-rails-4