title: Rails and jQuery: Javascript on page is reloading but not executing
body: <p>I am a newbie developing using rails and jquery and having been searching everywhere for a simple example of how to do this for days. I have a page, <code>poweroutput.html.erb</code>, that shows the power output of a customer's solar power system for a particular date. When they input a different date, I want them to see different output, but without having to reload the page. On my page I have some javascript as well as a form (for submitting the date for which a user would like to see the power output) as follows:</p>
  
  <pre><code>&lt;head&gt;
    &lt;script type="text/javascript"&gt;
      &lt;%= render "pages/poweroutputscript" %&gt;  # renders a partial containing all my js
    &lt;/script&gt;
  &lt;/head&gt;
  
  # a form is here on this page too
  </code></pre>
  
  <p>My page's controller action is currently as follows:</p>
  
  <pre><code>def poweroutput      
    # some code 
  
    if request.xhr?
      @date = params[:dt]         # dt is posted when form is submitted
    else 
      @date = Time.now.getlocal.strftime("%d.%m.%Y")
    end
  
    respond_to do |format|
      format.html 
      format.js { render :action "pages/poweroutput.js.erb" }
    end
  end
  </code></pre>
  
  <p>And poweroutput.js.erb is as follows:</p>
  
  <pre><code>$("script").html("&lt;%= escape_javascript render "pages/poweroutputscript" %&gt;");
  </code></pre>
  
  <p>As is, the form submits successfully and I can see on Firebug that the js between my script tags is indeed being replaced with the new js. But the view in my browser is not updating accordingly. What am I doing wrong? </p>