[英]Updating time_select data based on a collection_select option Using Ajax
I have a collection_select that lists all my venues. 我有一个collection_select,列出了我所有的场地。 Each venue has a different open and close time.
每个场所都有不同的开放和关闭时间。 So i am trying to update my time_select data based on the venue that was selected.
因此,我正在尝试根据所选地点更新我的time_select数据。
<%= collection_select(:game, :venue_id, Venue.all, :id, :name, prompt: true) %>
Right now i am hardcoding it. 现在,我正在对其进行硬编码。 I find a specific venue and assign the start_hour and end_hour to the venue's open and close times, like so:
我找到一个特定的场地,并将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}
Using javascript, I get the venue id when i select any from the list but cant figure out how to use ajax to update the start_hour and end_hour of the time_select based on the venue selected. 使用javascript,当我从列表中选择任意一个时,我会获得场地ID,但无法弄清楚如何使用Ajax根据选定的场地来更新time_select的start_hour和end_hour。
$('#game_venue_id').change(function(){
var venueId = $("#game_venue_id").find("option:selected").attr('value');
});
Help would be appreciated. 帮助将不胜感激。
Thank you. 谢谢。
Why no using a jquery? 为什么不使用jQuery? Example
例
<select class="combo_box"onchange="GetValue(this);"></select>
function GetValue(this){
var value = this.value;
}
regards 问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.