Jakob Toftegaard
Jakob Toftegaard

Reputation: 73

jquery submit fail in IE

I have a problem which some jquery, it works i chrome and firefox but not in IE

The code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js">
</script>
</head>

<body>

<form method='post' name='aform' action='test2.html'>
<input type='file' value='Upload Billede' name='image[fileupload]' /><input type='button' class='upload image[fileupload]' value='Upload Billede' />
</form>
<script type="text/javascript">
$(document).ready(function(){

bind_file_upload();    
});
function bind_file_upload()
{
    var target_id;
    $("[name='image[fileupload]']").change(function(event){
        $("[name='aform']").submit();
    });
    $(".upload").click(function(){
        $("[name='image[fileupload]']").click();
    });
}

</script>

</body>
</html>

The problem is that when i use the file control directly via the browse button the page submits, but when i use my own upload button it triggers the filedialog, but when i choose a file and press open jquery fail with permission denied.

What an i doing wrong.

Thanks in advance

Upvotes: 0

Views: 1294

Answers (2)

Frigik
Frigik

Reputation: 449

As Gregoire D. said, IE block your form submit as user clicks file input not directly. So for IE I use next solution

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

There are two possible solutions offered there. I prefer the first one (CSS based) solution.

Upvotes: 0

Gregoire D.
Gregoire D.

Reputation: 445

Your issue is that when you simulate the click on the file input, IE flag the form as a security threat, and won't send it. For IE you have to let the user click by himself on the file input.

EDIT:

If you really want to customize the file input, you may consider this : http://www.quirksmode.org/dom/inputfile.html

Or you can use a flash/silverlight plugin which you could customize as you want, or for internet explorer an ActiveX control.

Upvotes: 4

Related Questions