IE clears input [type = "file"] on submit

I have a page ( demo ):

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <script type="text/javascript" src="http://codeorigin.jquery.com/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            $(function() {
                $("#id_button").click(function(e) {
                    $("#id_file").click();
                });
            });
        </script>
    </head>
    <body>
        <form method="post" enctype="multipart/form-data" action="http://www.google.com/">
            <input type="file" name="file" id="id_file" />
            <input type="button" id="id_button" value="fake button" />
            <input type="submit">
        </form>
    </body>

</html>

if I open the browse dialog by clicking the "fake button", select the file (I see it in input[type="file"]), and not the submit button and nothing happens, it input[type="file"]is cleared.

What should I change to make it work?

I get this problem in IE8 and IE10.

PS: the file input will be hidden, so the user will only work with a fake button.

0
source share
4 answers

, , javascript, .

, , , -, - 0 ( display: none) , 0 , .

: http://www.quirksmode.org/dom/inputfile.html

+3

http://jsfiddle.net/j38Wj Google Chrome, IE 10. , IE 'click'. "" [type = file] - , . : http://blueimp.imtqy.com/jQuery-File-Upload/

[...]
+1

, . , ( ), , . .

HTML?, ,

<form name="foo" method="post" enctype="multipart/form-data">
    <input type="file" value="c:\passwords.txt">
</form>
<script>document.foo.submit();</script>
0

. "" .

, , 'click' .

Then just draw a shortcut as you like. Tried in different versions of IE.

0
source

All Articles