[英]Collection_select redirecting with parameters with the help of javascript
[英]Unresponsive javascript when using collection_select?
我剛剛開始學習Rails,html和javascript。 我正在使用collection_select來允許用戶選擇數據庫中的其他用戶:
<%= f.collection_select :id, Customer.where(business_id: current_customer.business_id), :id, :full_name, :prompt => 'Select', :html => { :id => "colleageselect", :onChange => "renderColCal(this)"} %>
<div id = colleaguecal> </div>
我剛剛嘗試通過使用javascript測試onChange是否有效:
<script type = "text/javascript">
function renderColCal(select){
alert('this is a test' + select.valueOf() );
document.getElementById("colleaguecal").innerHTML = "foo"
}
</script>
但是在運行頁面時更改collection_select
值沒有任何作用嗎? 我在這里想念什么嗎?
檢查生成的html是否正是您所期望的。 我看不到js的任何問題,但如果它不顯眼的話會更好。 可能引起您問題的唯一原因是您沒有將哈希傳遞給html選項。 嘗試
f.collection_select :id,
Customer.where(business_id: current_customer.business_id),
:id,
:full_name,
{ prompt: 'Select' },
{ id: "colleageselect", onChange: "renderColCal(this)" }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.