开发者

How to upload a file in just one click

I have HTML page, which gives an option to upload a file to the server, there is a servlet action class at server side & it handles request and write the file. Here how it works

  1. Click to Browse the file and select the file
  2. click the submit button.

But I want to upload in just one click on any button, please take a look of my code and suggest how to do that using javascript/jQuery fn.

<html> <head>  
  <script type = "text/javascript">
      function test() {
         var uploadfile = document.getElementByID("upload_id");
        uploadfile.click();  // here i can browse the file without clicking on file brows button
} </script>  </h开发者_如何学JAVAead> <body>

  <input type="button" id="just_one_click" value ="click me" onclick="test();" />

 <form action="upload.do" method="post" enctype="multipart/form-data">

   <input type="file" id="upload_id" name = "fileupload" />
   <input type = "submit" value="upload" />

 </form>  </body> </html> 


You can assign id (let's say 'myform') to your form and use document.getElementById('myform').submit(); instead of uploadfile.click();.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜