title: Send HTML form data to external javascript and send post request from Javascript
body: <p>I am trying to build a webpage where user enters phone number and that phone number is sent to server through HTML POST request, like this:</p>
  
  <pre><code>&lt;form action="/collectUserData" method="POST"&gt;
    &lt;div&gt;
      &lt;input name="to" value="Enter your phone number"&gt;
    &lt;/div&gt;
    &lt;div&gt;
      &lt;button&gt;Submit&lt;/button&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>However, I dont want to use this method because I also want to send the geo-coordinates of the user to the server, along with the phone number. The geo-coordinates can be captured through few lines of javascript.</p>
  
  <p>So what I want is, once the user enters phone number in the input text box and press the Submit button, the form data should be sent to a js file running in the same directory. Let the name of the js file be <code>sendUserInfo.js</code></p>
  
  <p>This js file should receive the phone number of user, determine coordinates, and then push the phone numnber and latitude to the server through a post request. </p>
  
  <p>The geo coordinate identification part is sorted out. Therefore, I need help regarding</p>
  
  <p>1) Sending form data to a js file running in same directory (strictly not in the HTML with <code>script</code> tag, but in a separate js file)</p>
  
  <p>2) Push the data from the javascript to server with a POST request.</p>
  
  <p>I searched on methods to do it quite a large but could not find methods which strictly do not use inline js with <code>&lt;script&gt;&lt;/script&gt;</code> tags whereas I need something with a separate js file. Any help will be appreciated.</p>
  
  <p><strong>Answers specific to node.js are most welcome.</strong></p>