TAGS :Viewed: 10 - Published at: a few seconds ago

[ Issue with file upload in one click ]

I'm using an icon instead of the regular upload input + submit button. I want the upload to starts automatically right after a file is chosen. Once the user selects a file, nothing happens though.

<form action="upload.php" method="POST" enctype="multipart/form-data">
  <input id="upload"  type="file" name="image"  style="display:none" value=/>
  <input name="wishid" type="hidden" value=/>
  <img id="upload_img" src="/images/upload.png">
</form>


<script type="text/javascript">
  $('#upload_img').click(function(){
  $('#upload').click();
 });
</script>

What do I need to add to the jQuery code to actually start the upload process via upload.php ?

Answer 1


Take a look at this description of how to replace input:file with image and then you can just use the code below...

<script type="text/javascript">
  $('#upload_img').click(function(){
    $('form').submit();
 });
</script>