[英]Updating time_select data based on a collection_select option Using Ajax
我有一个collection_select,列出了我所有的场地。 每个场所都有不同的开放和关闭时间。 因此,我正在尝试根据所选地点更新我的time_select数据。
<%= collection_select(:game, :venue_id, Venue.all, :id, :name, prompt: true) %>
现在,我正在对其进行硬编码。 我找到一个特定的场地,并将start_hour和end_hour分配给该场地的开放和关闭时间,如下所示:
@venue = Venue.find(1)
f.time_select :booked_from, {start_hour: @venue.open_time.to_i , end_hour: @venue.close_time.to_i, minute_step: 30, ampm: true}
f.time_select :booked_till, {start_hour: @venue.open_time.to_i , end_hour: @venue.close_time.to_i, minute_step: 30, ampm: true}
使用javascript,当我从列表中选择任意一个时,我会获得场地ID,但无法弄清楚如何使用Ajax根据选定的场地来更新time_select的start_hour和end_hour。
$('#game_venue_id').change(function(){
var venueId = $("#game_venue_id").find("option:selected").attr('value');
});
帮助将不胜感激。
谢谢。
为什么不使用jQuery? 例
<select class="combo_box"onchange="GetValue(this);"></select>
function GetValue(this){
var value = this.value;
}
问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.