Skip to content Skip to sidebar Skip to footer

Javascript Focus On Browse Button Of File Input

I am trying to focus on the browse button of the file input control. so I have something like and in javascript I have docume

Solution 1:

Can't be done. You have almost zero control over the constituent parts of a file upload field, partly for security reasons and partly because the standards do not define what constituent parts a file upload field might have. It is entirely possible the browser might render a file upload interface without any ‘Browse’ button.


Solution 2:

This question's been around for a while, allowing standards to evolve and develop with new functionality, but I've had success with the following code:

<input type="file" id="file_field" />

<input type="button" value="click me"
    onclick="document.getElementById('file_field').click()" />

I've managed to test it in Chrome and Internet Explorer 7, 8 and 9 so far, and I suspect it would work in Firefox too. Hope this helps someone!


Post a Comment for "Javascript Focus On Browse Button Of File Input"