title: Why this jQuery won't work when it's loading another function?
body: <p>This jQuery code should enable 2 actions.  </p>
  
  <p>1st action is auto-reloading page for every 7 seconds(refreshPartial();)<br>
  2nd action is auto input to <code>chat_box</code> field when a link is clicked.  </p>
  
  <p>2nd action works fine only if I remove 'refreshPartial();' from below.<br>
  Is it conflict error or something? How can I fix?</p>
  
  <pre><code>&lt;% if current_user %&gt;
      &lt;% content_for(:head) do %&gt;
          &lt;%= javascript_tag do %&gt;
  
              jQuery(document).ready(function () {
  
                   refreshPartial();
  
                   $('a#username').click(function() {
                       $(".chat_box#body_input").val($(this).attr('value'));
                   });
  
              });
  
  
              function refreshPartial() {
                $.ajax({
                  url: "&lt;%= show_user_path(@user) %&gt;/refresh_part?page=&lt;%= params[:page] %&gt;",
                  type: "GET",
                  dataType: "script",
                });
              }
  
          &lt;% end %&gt;
      &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>refresh_part.js.erb</strong></p>
  
  <pre><code>$('#chat_comment').html("&lt;%= j(render(:partial =&gt; 'users/comment')) %&gt;");
  setTimeout(refreshPartial,7000);
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>def refresh_part
      @comments = @user.comment_threads.order("updated_at DESC").page(params[:page]).per(10)
      @comment = @user.comment_threads.build
  
      respond_to do |format|
          format.js 
      end
  end
  </code></pre>
  
  <p><strong>View(Form input field)</strong></p>
  
  <pre><code>&lt;a name="comment_part"&gt;&lt;/a&gt;
  &lt;form accept-charset="UTF-8" action="/users/John_Smith/comments" class="new_comment" data-remote="true" enctype="multipart/form-data" id="new_comment" method="post"&gt;
      &lt;input name="utf8" type="hidden" value="&amp;#x2713;" /&gt;
      &lt;input name="authenticity_token" type="hidden" value="vvwHabqywaDXv0Sv5NrbPP5kfdwhfewovbHkegkOUm2/2uJdNs=" /&gt;
      &lt;input class="chat_box" id="body_input" name="comment[body]" type="text" /&gt;  
      &lt;button type="submit" class="btn"&gt;Submit&lt;/button&gt;   
  &lt;/form&gt;
  </code></pre>