0

I encounter a problem with a file upload form when I use Internet Explorer (9). My form is a little special because I simulate a secondary behavior on my both inputs :

  • For the input[type=file], after the user selects a file, I submit the form.
  • For the input[type=submit], before he submits the form, I open the file browser and once he selects a file, I submit it.

The my script works with Chrome and FF but not IE. Indeed when I test the submit button the form is not sent whereas when I use the input[type=file], I don't have any problems.

Here is the HTML:

<form name="up" action="/" method="post" enctype="multipart/form-data">     
    <div class="fileinputs">
        <input type="file" name="FILE" size="38" class="file" id="upload" onchange="submitForm()" />
        <input type="submit" value="BROWSE" name="ok" class="submit" id="submit_button_id" onclick="return check();" />
    </div>
</form>

JS :

function submitForm() {
    document.getElementById("submit_button_id").click();
}

function check()
{
    var path = false;

    document.getElementById('upload').click();

    var filesent = document.getElementById("upload");
    filesent.value === "" ? path = false : path = true;

    if(!path){
        return false;
    }

    return true;
}
Adrien G
  • 1,086
  • 2
  • 14
  • 32
  • 1
    This is why you should use `event.preventDefault()` instead of messing around with `return` inconsistencies. As well as binding events unobtrusively – Ian Jun 03 '13 at 15:44
  • this, though somewhat old, should be of some help http://stackoverflow.com/a/3030174/1236044 – jbl Jun 03 '13 at 15:59

0 Answers0