I have the following code to submit a form and call a PHP script.
<script>
function handleBrowse()
{
$('#uploadedfile').click();
}
function displayFilePath(obj)
{
document.getElementById('dummyFilePath').innerHTML = obj.value;
}
</script>
<div id="dummyFilePath" class="dummyFilePath"></div>
<input type="button" value="Browse" onclick="handleBrowse();"/>
<form enctype="multipart/form-data" action="../php/uploader.php" method="POST" target="myiframe">
<input type="file" id="uploadedfile" name="uploadedfile" onchange="displayFilePath(this)" style="display:none"/>
<input type="submit" value="Upload File" />
</form>
<iframe name="myiframe" id="myiframe" src="" width=1 height=1 style="visibility:hidden;position:absolute;bottom:2px;"></iframe>
In Firefox I would only have to click once to submit it. But in IE, I need to click twice!
Could you explain me why?
Please run this jsFiddle on IE to see the problem. You can clearly see that once you browse for a file to upload, unless you press the upload file button twice the form's action does not work.
PS: the double click issue in IE can be resolved as suggested in the answer below, but that would cause the uploaded file never to reach its destination (uploader.php); Only its name will