So here’s the scenario-
Unlike the 3000 other questions on StackOverflow about how to INVOKE the click event on an input[type=file] element, I just want to respond to it. I’m looking for something like:
<input id="theFile" onclick="var that=this;setTimeout(function(){if(that.value){postTheForm();}}),0);" />
I’m not trying to call click() on the element, I just want to know when someone has selected a file so it we can submit the form. In IE, it works as expected, because the file dialog box sleeps the javascript thread until the user clicks Open or Cancel in the dialog. In FireFox, it seems like the dialog does not sleep the thread, and the anonymous function fires immediately – even while the dialog is still up.
I was thinking may I could use the onchange event, or something else in FireFox to simulate the IE behavior, but haven’t had any luck so far. Any ideas as to how I can execute code AFTER the user clicks Open or Cancel in the dialog?
use:
onchange="submitForm()"