我想将从我的collection_select下拉列表中选择的值传递给onchange函数。当我的名字,我的价值打印为来源[指数],但我想这不是作为文本本身的价值。你如何将值从collection_select传递给Rails中的onchange函数?
<%= collection_select(:source, :index, @sources, :id, :name, options = {include_blank: "Please select a source..."}, html_options = {:onchange => "updateTextArea(name)"}) %>
function updateTextArea(source){
var value = source;
console.log(value);
}
如果我不使用表格?这是一个独立的下降。 – A21
好吧,试试不用'f' –
这就是我在我的问题中所做的。我可以让下拉菜单正确显示。但是,传递给onchange函数的值不会打印出在下拉列表中选择的值。 – A21