フォームのselectが変更されたら何かする
いい表題ではないな、、、
_form.html.erb
<% content_for :html_header do -%> <script type="text/javascript"> <!-- window.onload =function(){ /*prototype.jsで書く*/ Event.observe("rental_moving", "change", handler); } function handler(e){ var rental_moving = $F("rental_moving"); alert(rental_moving); } --> </script> <% end %> ・・・ <td><%= f.select(:moving, Rental::MOVING) -%></td> ・・・
Event.observeのchangeで変化を読み取って、関数を呼び出して、$F("rental_moving")でHTMLのIDの値を取得する。
jQueryに慣れていると面倒な手続きだね。