title: How to create Jquery external file?
body: <p>I want to create external JS file for the form and post that data using AJAX.</p>
  
  <p>The simplified HTML looks like:</p>
  
  <pre><code>&lt;form action="" id="message" name="message" method="post"&gt;
  &lt;input name="message_subject" type="text"  id="message_subject" class="message_wall" /&gt;
  &lt;textarea cols="50" rows="5" id="message_text" class="message_wall"&gt;&lt;/textarea&gt;
  &lt;button type="submit" id="mess" class="mess"&gt;send&lt;/button&gt;
  </code></pre>
  
  <p>The Jquery that I'm currently using for this form:</p>
  
  <pre><code>$("form#message").submit(function() {
    var message_subject = $(".message_subject").attr('value').replace(/\n/g,"&lt;br/&gt;").replace(/\n\n+/g, '&lt;br /&gt;&lt;br /&gt;').replace(/(\&lt;\/?)script/g,"$1noscript");
    var message_text= $(".message_text").attr('value').replace(/\n/g,"&lt;br/&gt;").replace(/\n\n+/g, '&lt;br /&gt;&lt;br /&gt;').replace(/(\&lt;\/?)script/g,"$1noscript");
    $.ajax({
      type: "POST",
      url: "mess/somefile.php",
      contentType: "application/x-www-form-urlencoded;charset=ISO-8859-2",
      data: "message_subject="+ message_subject + "&amp;message_text=" + message_text,
      success: function(){
        $(".message_field").html('Thanks!');
      }
    });
    return false;
  });
  </code></pre>
  
  <p>Can I this Jquery code be put in an external JS file and then called like:</p>
  
  <pre><code>$(document).ready(function(){
    myexternalfunction();
  });
  </code></pre>