-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>

1
  • Why do you mark this as duplicate and a negative points if we never heard of JQuery's trigger? Shaking my head Commented Mar 14, 2014 at 15:35

1 Answer 1

1

You can use jQuery's trigger method like this:

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

You can read more in jQuery's documentation here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks.. I never heard of trigger.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.