title: How to upload a file in just one click
body: <p>I have HTML page, which gives an option to upload a file to the server, there is a servlet action class at server side &amp; it handles request and write the file. <strong><em>Here how it works</em></strong>   </p>
  
  <ol>
  <li>Click to Browse the file and select the file</li>
  <li>click the submit button.</li>
  </ol>
  
  <p>But I want to upload in just one click on any button, please take a look of my code and suggest how to do that using javascript/jQuery fn.  </p>
  
  <pre><code>&lt;html&gt; &lt;head&gt;  
    &lt;script type = "text/javascript"&gt;
        function test() {
           var uploadfile = document.getElementByID("upload_id");
          uploadfile.click();  // here i can browse the file without clicking on file brows button
  } &lt;/script&gt;  &lt;/head&gt; &lt;body&gt;
  
    &lt;input type="button" id="just_one_click" value ="click me" onclick="test();" /&gt;
  
   &lt;form action="upload.do" method="post" enctype="multipart/form-data"&gt;
  
     &lt;input type="file" id="upload_id" name = "fileupload" /&gt;
     &lt;input type = "submit" value="upload" /&gt;
  
   &lt;/form&gt;  &lt;/body&gt; &lt;/html&gt; 
  </code></pre>