title: How to use onchange in ruby form?
body: <p>I am trying to build an interactive search page that update the search result if any change is made to the search form without refreshing the page. I was able to make show the result without refreshing but I still need to click on the search button after I change anything.</p>
  
  <p>My view:</p>
  
  <pre><code>&lt;div class="row"&gt;
    &lt;div class="col-md-2 col-md-offset-5"&gt;
  
      &lt;%= form_for(:search, url: search_path, remote: true) do |f| %&gt;
  
        &lt;%= f.label :course_name %&gt;
        &lt;%= f.text_field :course_name, class: 'form-control bottom_margin', onchange: f.submit %&gt;
  
        &lt;%= f.label "Subject" %&gt;
        &lt;%= collection_select(:search, :subject_id, Subject.all.order(:name), :subject_id, :name, :prompt =&gt; true, onchange: f.submit)  %&gt;
  
        &lt;%= f.submit "Search", class: "btn btn-primary top_margin" %&gt;
      &lt;% end %&gt;
    &lt;/div&gt;
  
  &lt;/div&gt;
  &lt;div id="result"&gt;
  &lt;/div&gt; 
  </code></pre>
  
  <p>My controller:</p>
  
  <pre><code>class SearchController &lt; ApplicationController
    def new
    end
    def create
      @course = search_params[:course_name]
      @subject = search_params[:subject_id]
      if @subject == ""
        @searchResults = Course.all
      else
        @searchResults = Subject.find_by(subject_id: @subject).courses
      end
  
      @searchResults = @searchResults.where("name LIKE ?", "%#{@course}%")
      respond_to do |search|
        search.js {render layout: false}
      end
    end
    private
      def search_params
        params.require(:search).permit(:course_name, :subject_id)
      end
  end
  </code></pre>
  
  <p>My JavaScript:</p>
  
  <pre><code>$("#result").html("&lt;%= escape_javascript(render partial: 'search/create', locals: { searchResult: @searchResult } ) %&gt;");
  </code></pre>
  
  <p>Why is on change not working?</p>