1

I have created a fake file input using an anchor tag and placed a hidden file input beside this, I want to use jquery to add a click event to the anchor tag that triggers the activation of the hidden input box but Im not completely sure how to achieve this, if anyone could give me some advice that would be great.

Here is my current effort http://jsfiddle.net/kyllle/CdXP9/

I guess Im probably way off with this one, would love some advice on how this can be achieved though

Kyle

3 Answers 3

10

http://jsfiddle.net/CdXP9/6/

$('#upload').css("visibility", "hidden");

$('#fakeUpload').click(function(e) {
    e.preventDefault();
    $('#upload').trigger('click');   
});
Sign up to request clarification or add additional context in comments.

1 Comment

Note that this isn't that simple for IE6/7/8 and FF because of security concerns. There are developers and shops that have spent a ton of time figuring this out and you might be better off trying a jQuery plugin or a component: krystalware.com/slickupload
1

I cannot say for certain that it isn't possible, but js code to automatically upload a file is very much frowned on, and deliberately made difficult. So I think you are probably on a hiding to nothing with this.

1 Comment

OP isn't trying to auto upload, just trying to trigger the "Select File" dialog from the anchor tag.
0

Use the click function it will open the browse window- if that's what you want- see http://jsfiddle.net/CdXP9/5/

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.