views:

386

answers:

2

hi, is it possible to show "choose file" window, when i click on some image ? i want to hide that input and browse button, which shows when i type thanks

A: 

No, because of security restrictions in the browser. You have to go with Flash or Java to achieve that.

Tim Jansson
+1  A: 

Long answer: Yes, you absolutely can. Get ready for some Javascript/CSS haxx that I cooked up. First the Javascript:

function getFilePathFromDialog() {
    document.getElementById('fileBrowser').click();
    document.getElementById('filePath').value = document.getElementById('fileBrowser').value;
}

Now the HTML:

<img src="path/to/image.jpg" onlick="getFilePathFromDialog();">
<input type="text" id="filePath" name="filePath" /><br />
<input type="file" id="fileBrowser" name="fileBrowser" style="visibility:hidden; display:none;" />

Basically all this does is hide the actual file dialog input field from view. When you click on your image it will fire the file dialog's click event. When the user chooses a file and clicks "Open", it will put the file path selected in the textbox called "filePath".

Mr. Smith
P.S: You can use jQuery (if you use that) to achieve the same effect, this is just pure JS.
Mr. Smith

related questions