title: Trigger the html file-browser click event in javascript/jquery?
body: <p>So what's wrong with this script?  I'm trying to trigger the file browser onclick event which is not working.  </p>
  
  <p>Thanks...</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;script type="text/javascript" src="jquery-v2.0.3.min.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript"&gt;
    function foo()
    {
        //height:0px;overflow:hidden;
          if ($('#WebFormFileUploadMalsup').length == 0) {
              $('body').append('&lt;div style=""&gt;&lt;form id="WebFormFileUploadMalsup" name="WebFormFileUploadMalsup" method="post" action="../websrvc/PhotoServerIntegration.ashx" enctype="multipart/form-data"&gt;&lt;input type="hidden" id="WhichWebAction" name="WhichWebAction" value="VehicleImagesUpload" /&gt;&lt;input type="file" id="FormButtonFileBrowserMalsup" name="myfile[]" multiple onChange="document.getElementById(\'FormButtonFileUploadMalsup\').click();" OnClick="alert(\'Please click button to upload after you are done browsing with files.  Maximum file-size is 8 MB.\');"&gt;&lt;input type="submit" id="FormButtonFileUploadMalsup" value="Upload File to Server"&gt;&lt;/form&gt;&lt;/div&gt;');
          }
  
  
          //alert(document.getElementById('FormButtonFileBrowserMalsup'));
          //if (!(document.getElementById('FormButtonFileBrowserMalsup')))
          if ($('#FormButtonFileBrowserMalsup'))
          {
              alert("Error");
          }
          else
          {
              //#//Document.getElementById() works better than using JQuery's on() click event...
              //#//$('#FormButtonFileBrowserMalsup').on("click", function () { alert("ggg"); });
                                //#/document.getElementById('FormButtonFileBrowserMalsup').onclick = fucntion() { this.click(); };
              var $foo = $(document.getElementById('FormButtonFileBrowserMalsup'));
                 //alert($foo);
                 $foo.on("click", function() { alert("hhh"); });
        }
    }
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
  &lt;form id="web" name="web"&gt;
    &lt;input type="button" value="Open Me" onclick="foo();" /&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>