Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7538001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:59:56+00:00 2026-05-30T06:59:56+00:00

The idea is: you have a file field, which is hidden, and an image.

  • 0

The idea is: you have a file field, which is hidden, and an image. You use the image to show the select file dialog. Then I display the image in the canvas.

<input id="ytfile-select" type="hidden" value="" name="Foto[image]" />
<input style="display:none" id="file-select" accept="image/*" 
name="Foto[image]" type="file" />
<img id="upload-image" src="/images/design/upload-image.png" 
alt="upload-image-button" />        
<canvas id="canvas">  
    Sorry, your browser doesn't support the &lt;canvas&gt; element.  
</canvas>  

$('#upload-image').click(function(){
  $('#file-select').click();
});


$('#file-select').bind('change',function(){
  var fileList = this.files;  
  var img = document.createElement("img");  
  img.classList.add("obj");  
  img.src = window.URL.createObjectURL(fileList[0]);  
  var ctx = document.getElementById('canvas').getContext("2d");
  ctx.drawImage(img,0,0);
});

On Firefox 10, ctx.drawImage(img,0,0); only works when I have the Firebug debugger nad breakpoint on that line. Without the breakpoint, it doesn’t work. I checked it on another clean profile.

On Chrome, $('#file-select').click(); doesn’t open the file dialog.


Edit: this question has been already answered. However, I have no idea what the issue with Firefox is. Any ideas?

I used these websites to create this code:

  • https://developer.mozilla.org/en/using_files_from_web_applications
  • http://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/

Edit 2:
I resolved the issue with the Firefox by doing this:
Behind the line var fileList = this.files;, I put:

reader = new FileReader();
reader.onload = function (event) {
    $('#display').append('<img src ="' + event.target.result + '">');
};
reader.readAsDataURL(fileList[0]);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:59:58+00:00Added an answer on May 30, 2026 at 6:59 am

    This will trigger the click event:

    $('#file-select').trigger("click");

    Example:

    <input type="file" id="filesel" name="file" style="position:absolute;left:-999px;top:-999px" />
    <a onclick="$('​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​#filesel').trigger('click');" href="#">click to open</a>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
    

    JSFiddle demo: http://jsfiddle.net/t7P3v/

    Update:

    Indeed, if the input type="file" is display:none it will not pop up. Still you can make it invisible to the user by some CSS: position:absolute; top:-999px; left:-999px

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an insane idea: use .hta file as the gui front end of
I have a very little idea about what database file system is. Can somebody
Note: I have almost no idea at all how batch file 'for' loops work.
I'm coding a form using PHP and jQuery. I have a file upload field
I have a big file that can't fit in the memory which I would
I have a upload field where people can upload a image. I'd like to
I am new to unix commands. I have a file named server.txt, which has
I have a php file which performs a series of insert queries. If any
I have a custom 'Player' node type in Drupal with a CCK file field
Greetings, I have a particular object which can be constructed from a file, as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.