我想將從我的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