I already looked all around, and can't find a solution: I have a form to upload files, and it should fire the submit after the file selection.
On FF/Chrome it goes weel, and submit the form after file selection, but I can't do this on ie.
Already tried with click/propertychange but nothing happens. Some code I already tried:
$("#attach").attr("onChange", "alert('I changed')");
$("#attach").live($.browser.msie? 'propertychange': 'change', function(e) { ... });
Any sugestions to I try?
Edit1: I think there's a important information, this input file, is created on the fly, because of it I use .live() to bind the event
This is really late, but I was having the same problem, and I solved it by using a styled
<label>
tag with a slight workaround for Firefox.http://jsfiddle.net/djibouti33/uP7A9/
The Goals:
The Browsers:
The Initial Solution:
The Problem:
The Workaround Solution:
Hope this helps! Check out the jsfiddle for details on the html/js/css used to make it all work.
I was having the same issue with IE (including IE 9). The UI logic is:
div
element triggers theclick
event on afile-input-element
so that user click on adiv
trigger file open dialogchange
event handler to thefile-input-element
to ensure theform
is submitted when file open dialog closedThe app (running inside an iframe) works like a charm on Chrome and FF. But soon I found it doesn't work on IE as when user selected a file and close the dialog the form didn't submit.
The final solution is to drop the logic #1 "click on
div
element triggerclick
event on file input element" and let user to click on thefile input element
directly, and then it works.BTW, the reason we have a
div
element is we want to hide the browser rendered controls because we have everything in the background image. However setdisplay
tonone
makes the control not able to respond a user interaction event. So we move thefile-input-element
to outside of the view port and use adiv
element to replace it. Since this doesn't work on IE, we end up with move back thefile-input-element
and set it'sopacity
to 0. On IE 8 or less which doesn't supportopacity
, we use filter to make it transparent:This has always worked for me in IE6 ad IE7.
It works in IE, but if you want to emulate "live" behavior, you should add "onChange" attribute to each new element when create its.
In IE onchange event works fine when it filled out in html tag directly. Like:
For IE You can use the "onfocus" event to catch the change of uploading file. Once the file browsing dialog is closed the onfocus event is triggered. You can check this by adding this line to your page:
<input type="file" onfocus="javascript:alert('test');" />
Once the dialog is closed the alert message is shown.
This solution is only for IE, not for FF or Chrome.