-1

So what's wrong with this script? I'm trying to trigger the file browser onclick event which is not working.

Thanks...

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <script type="text/javascript" src="jquery-v2.0.3.min.js"></script>
  <script type="text/javascript">
  function foo()
  {
      //height:0px;overflow:hidden;
        if ($('#WebFormFileUploadMalsup').length == 0) {
            $('body').append('<div style=""><form id="WebFormFileUploadMalsup" name="WebFormFileUploadMalsup" method="post" action="../websrvc/PhotoServerIntegration.ashx" enctype="multipart/form-data"><input type="hidden" id="WhichWebAction" name="WhichWebAction" value="VehicleImagesUpload" /><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.\');"><input type="submit" id="FormButtonFileUploadMalsup" value="Upload File to Server"></form></div>');
        }


        //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"); });
      }
  }
  </script>
</head>
<body>
</body>
<form id="web" name="web">
  <input type="button" value="Open Me" onclick="foo();" />
</form>
</body>

fletchsod
  • 3,560
  • 7
  • 39
  • 65
  • Why do you mark this as duplicate and a negative points if we never heard of JQuery's trigger? **Shaking my head** – fletchsod Mar 14 '14 at 15:35

1 Answers1

1

You can use jQuery's trigger method like this:

$('#id').trigger('click')

You can read more in jQuery's documentation here

Petar Vasilev
  • 4,281
  • 5
  • 40
  • 74