开发者

Auto submit form every time when someone selects file

开发者 https://www.devze.com 2023-02-19 08:11 出处:网络
I have a form with only one file input and I want to auto submit the form every time when someone selects file. Now I use this code:

I have a form with only one file input and I want to auto submit the form every time when someone selects file. Now I use this code:

$(function(){
    $("#fil1").change(function(){
        $("#form1").submit();
    });
});

but it works only for the first selection. When I select some other 开发者_如何学JAVAfile the form is't submitted again! It seems the change function is called only for the first time! Can anyone help? I use jquery...


What version of jQuery are you using? I just tried the code below and it worked multiple times. Also wonder if it's your browser. I tried Chrome and IE 8.

<html>
<head>
<title>index.html</title>
<script type="text/javascript" src="js/jquery/jquery-1.5.1.min.js"></script>  
<script type="text/javascript">  
alert('hit');
$(function(){
    $("#fil1").change(function(){
        $("#form1").submit();
    });
});
</script> 

</head>

<body> 

<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <label for="fileField"></label>
  <input type="file" name="fileField" id="fil1">
</form>
</body>
</html>

hope this helps...

0

精彩评论

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