Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  14] [ 5]  / answers: 1 / hits: 90394  / 15 Years ago, tue, december 1, 2009, 12:00:00

Possible Duplicate:

In JavaScript can I make a “click” event fire programmatically for a file input element?






I've got a web page that looks like this



<html>
<head>
<title>File Upload Click Test</title>
<script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script>
</head>
<body>
<div onclick=$('input[type=file]').click() >CLICK SIMULATOR</div>
<input type=file></input>
</body>
</html>


My goal is to have the div raise a click event on the file input, and this seems to work exactly as I'd expect in IE and Chrome, but doesn't work in Firefox (no file browser is opened when you click on the div).



Is there a way to get this working in FF?


More From » jquery

 Answers
390

Is there a way to get this working in FF?




No, and it doesn't work in most common versions of IE, either. IE will open the dialog, but once you've selected a file with it the form won't actually submit.



Abandon hope. The only way to fake a file upload box is using the transparency technique, and that's really not recommended at all as browsers may lay out file upload boxes differently internally (or even provide a file upload control that doesn't include a Browse dialogue), making it highly likely you'll end up with an inoperable form.



Learn to love the grey file upload field, or use progressive enhancement to replace it with Flash where available.


[#98180] Friday, November 27, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
longd

Total Points: 616
Total Questions: 110
Total Answers: 101

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
;