select_tag in rails about selected not change and onchange()

make it more easy after http://www.cnblogs.com/juandx/p/4058399.html

1  if you want the selected is what you choose after you submit the form use javascripts, then you should do this  selected: params[:option] in options_for_select();

2  if you want to submit after you change the select tag immediately,you should use onchange: "this.form.submit();"  ofcouse the ";"  is not necessary;

<%= form_tag("monitor",:id => "idform",name: "idform",method: "get") do |f| %>
时间间隔:
<%= select_tag :times, options_for_select([["second","_10seconds"],["minute","_5minutes"],["hour","_hour"],["day","_day"],["week","_week"],["month","_month"],["year","_year"]] , selected: (params[:times]==nil ? "_5minutes" : params[:times]) ), onchange: "this.form.submit();" %>
      
列数:
<%= select_tag :col, options_for_select([["1","1"],["2","2"],["3","3"],["4","4"],["5","5"],["6","6"],["7","7"],["8","8"],["9","9"],["10","10"]], selected: (params[:col]==nil ? 2 : params[:col]) ), onchange: "this.form.submit();" %>
   
<%= submit_tag("刷新") %>
<% end %>

  

上一篇:Docker 私有仓库 Harbor registry 安全认证搭建 [Https]


下一篇:XLAT转码:以DS:【BX+AL】为地址,提取存储器中的一个字节再送入AL