簡體   English   中英

使用Ajax根據collection_select選項更新time_select數據

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM