0

I'm in a sticky situation. I'm trying to make an image an upload button, but I cannot change that image at all... however, when you click the image, I have it calling a JS function I can put anything into.

How can I launch an browser upload though this function alone? Normally I would just make the image an input, but like I said, in this case I cannot do that.

Does anyone have an example they could share?

Here's my function (which is called onclick of the image):

 function fnImport(elem){
    var $input;

    $input = $input || $("<input type='file'>");
    $('#Import').append($input);
    $input.click();
    $input.hide();



    }

However, when I run it, on the first click it adds the button, then on second it acts as an upload (and doesn't hide in either).

In addition, I'm getting a strange as well in my console?

2
  • you can't just launch an upload just by calling something. That is a matter of security. If it would be possible a website could automatically upload data from the user machine without the knowledge of the user Commented Oct 12, 2012 at 18:08
  • By launching an upload, I may have not been clear. I mean, I just want the computer file browser to appear, as if they clicked on "<input type="file">, not an automatic upload of something on their computer. Commented Oct 12, 2012 at 18:11

1 Answer 1

1

Something like this might spark some ideas for you: http://jsfiddle.net/NKekN/2/

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

2 Comments

This is amazing! Exactly on the lines I was thinking. However, I'm having trouble placing it inside my pre-existing click function. I've updated my question with some code (and added a hide to the input field you added!) -- could you help me sort this out by chance?
Works perfect -- was having trouble fitting into my code for a second. Thank you for your help!

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.