I have a photo upload form that I'm working on that works like this:
- You click an "Upload Photo" button. jQuery detects the click and triggers a click event to a hidden "file" field within the form, which brings up a dialog to search through your files.
When the user selects a file, the change event is detected on the hidden file field and triggers a form submission. Here is the code:
// on photo upload button click: $("input[name=PhotoUpload]").click(function() { $("input[name=Photo]").click(); }); // on photo upload: $("input[name=Photo]").change(function() { $("form[name=MediaUpload]").submit(); });and the form:
<form name="MediaUpload" method="post" action="/postad/media.cfm" target="Media" enctype="multipart/form-data"> <input type="button" name="PhotoUpload" value="Upload Photo"> <input type="file" name="Photo" size="30" style="visibility:hidden;"> </form>
This works great in Chrome and FireFox, but am having no luck in any version of IE. Any suggestions?
focus()to be assigned to a hidden element, which would probably preclude theclick()event too.