开发者

Problem with file submiting

开发者 https://www.devze.com 2023-03-29 16:14 出处:网络
<form method=\"POST\" enctype=\"multipart/form-data\" action=\"http://site.com/img\"> File: <input type=\"file\" name=\"file\" id=\"abc\" /><br/>
<form method="POST" enctype="multipart/form-data" action="http://site.com/img">
File: <input type="file" name="file" id="abc" /><br/>  
ID: <input type="text" name="someId" value="123"/>
<input id="submitFormButton" type="submit" value="Upload" name="Upload"> 
</form>

&l开发者_如何学JAVAt;input type="button" id="btnEditAvatar" value="fakeButton"/>

$("#btnEditAvatar").bind("click", function () { $("#abc").trigger("click"); });
$("#abc").change(function() { $("#submitFormButton").trigger("click"); });

Problem occurs in IE only. When choose file by pressing on "abc" button it works(after closing file dialog, file is uploaded), but when I press on "btnEditAvatar" button, nothing is happened after closing file diaog.

I've tried to use "click" function instead of "change". I've tried to call it with "setTimeout" function and I also tried to use "onpropertychange" event handler.

http://jsfiddle.net/streamcode9/hAnbQ/


Instead if trying to click the submit button, why not just submit the form?

$("#abc").change(function() { $(this).closest('form').submit() });


try either of these:

$("#btnEditAvatar").bind("click", function () { $("#submitFormButton").trigger("click"); });
$("#abc").change(function() { $("#submitFormButton").trigger("click"); });

This binds it to submit.

$("#btnEditAvatar").bind("click", function () { $("#abc").trigger("change"); });
$("#abc").change(function() { $("#submitFormButton").trigger("click"); });

this binds it to change which triggers the submit click

0

精彩评论

暂无评论...
验证码 换一张
取 消