2013-01-23 55 views
0

我正在從很長一段時間開始工作。我想在一個下拉菜單中顯示一個集合的元素,點擊一個值,我必須重新加載這個頁面並顯示它的細節。這我很容易做到。問題是,當頁面重新加載時,下拉列表中的所選值將被重置。所以我只想在重新加載之後保留選定的值以使用':selected'屬性,以便在重播之後顯示點擊的值。所以請讓我知道如何儘快解決這個問題。請幫我解決這個問題。重新加載後顯示下拉菜單的選定值

<%= form_tag({},:method => :get, :class => 'formSearch absolute') do %> 
    <%=select("post", "id", @other_schools.collect {|p| [ p.name, p.id ] }, { :include_blank => true }, :onchange => "this.form.submit();") %> 
    <%end%>               
+0

你有選擇selecetd可能會粘貼代碼片段幫助更多 – Amar

+0

請仔細閱讀此問題。我已經將代碼添加到了它。 – Karthikds

回答

0

根據你的代碼, 您是基於選擇框的值搜索和要填充搜索選項

我會用select_tag更多信息here

<%=select_tag("post_id", options_for_colletcion_select(@other_schools,p.name, p.id ,params[:post_id), { :include_blank => true }, :onchange => "this.form.submit();") %>

你可以閱讀文檔以獲取語法選項。

+0

謝謝。它現在運作良好.. – Karthikds

+0

如果它適合你,你能接受答案嗎? – Amar

0

在這段代碼中,this.form.submit();方法會去哪裏?

<%=select_tag("post_id", options_for_colletcion_select(@other_schools,p.name, p.id ,params[:post_id), { :include_blank => true }, :onchange => "this.form.submit();") %>