0

I'm currently trying to restyle (eclipse) a fileupload element on my website with this reference. All well and the result is promising, when I put the fileupload element below my new alternative image (as instructed on afore mentioned tutorial). Now I want to place the fileinput element somewhere else and bind a click function on the image to a click on the fileinput element to fire a file browser dialog.

Alas the usual $('input:file').click() or $('input:file').trigger('click') is not working.

I'm also interested in other ways to fire a file dialog, without a file upload element (it is only for javascript processing, no upload to the server).

Oh it does not need to work on any version of IE.

3
  • Shouldn't that be $('input:file').click()? (apostrophe after file) Commented Jun 15, 2011 at 13:18
  • possible duplicate of Jquery trigger file input Commented Jun 15, 2011 at 13:36
  • @bazmegakap yep missed that one. Commented Jun 15, 2011 at 13:55

3 Answers 3

5

Missing a quote on both your code samples, try $('input:file').trigger('click') However, as far as I know, it's not possible to do this, at least this way. It's by design that way, on purpose, for security issues.

You can try to do it by tracking mouse movement and move the hidden file input on top of the new image or whatever you will use to style the input.

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

1 Comment

hmm, I didn't notice that. Sharp! +1
3

How are you doing it right now, can you give us some more code? Also try adding a unique ID to the file input and the field you want to trigger. For example:

<span id="browse">Click here to choose a file</span>
<input type="file" id="file" />

Then try doing:

$('#browse').bind('click', function(e) {
  $('#file').click();
});

3 Comments

but when you try to copy the fileupload path to textbox by using change event, it is not working in IE 8,9,10.
id is not a requirement, any selector matching the input would work
that surely would work great with multiple input fields on your page.
0
<div class="imageUploadInput">
    <img id="uploadImage" src="images/camera_icon.png" />
    <input type="file" name="thumb" id="uploadImageInput" />
</div>

jQuery:

$('#uploadImage').livequery("click",function(){
    $('#uploadImageInput').trigger('click');
});

or

$('#uploadImage').click(function(){
   $('#uploadImageInput').trigger('click');
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.