0

Im trying to create a FORM File input button with my custom styles.

Below is the code, but it doesnt work.

<style type="text/css">
 .pictures { width:200px; height:70px; overflow:hidden;}
    input{position:absolute; top:-100px;}
</style>


<form id="test_form" method="post">

<div class="pictures">
  <input type="file">
  <button>Upload</button>
      <label>No file selected</label>
</div>

<div class="pictures">
  <input type="file">
  <button>Upload</button>
      <label>No file selected</label>
</div>

<div class="pictures">
  <input type="file">
  <button>Upload</button>
      <label>No file selected</label>
</div>

</form>

<script>
    $(function(){
        $("button").click(function() {
        var $this = $(this),
            inputVal = $this.closest('input').val();

        $this.closest('input').click(
            function(){
                $(this).change(function(){
                    $this.closest('label').text(inputVal);
                });
            }
        );      

    })  
    });
</script>
STEEL
  • 8,955
  • 9
  • 67
  • 89
  • This is triggering click now, but Label text doesnt fill up. $("button").click(function() { var $this = $(this), inputVal = $this.prev().val(); //$this.prev().trigger('click'); $this.prev().trigger('click', function(){ $(this).change(function(){ $this.next().text(inputVal); }); } ); }); – STEEL Apr 26 '13 at 11:06

1 Answers1

0

It may be worthwhile for you to check out this post: How can I upload files asynchronously?

A quick Google search for "jQuery file upload" also shows that there are several plugins that are available to accomplish what you're trying to do, and it's likely that you'd be able to customize the styling for those plugins to make them look how you'd like.

I personally love this one by blueimp.

Community
  • 1
  • 1
Dylan R
  • 213
  • 3
  • 11