1

I want to create an upload form, which always presents a new file input, when filled out. I tried to make this work by creating new inputs but it just works once.

Here is the code:

<head><script type="text/javascript" src="jquery-1.7.2.min.js"></script></head>
<body><form>
  <div id="to"></div>
  ---
  <div id="from"><input type="file" class="new"></div>
</form>
<script type="text/javascript">
  $('.new').change(function() {
    $('.new').appendTo('#to').removeClass('new');
    $('#from').append('<input type="file" class="new">');
  });
</script>
</body>
Jason Aller
  • 3,475
  • 28
  • 40
  • 37
yajRs
  • 91
  • 1
  • 1
  • 7

4 Answers4

1
<script type="text/javascript">
  $('.new').on('change',function() {
    $('.new').appendTo('#to').removeClass('new');
    $('#from').append('<input type="file" class="new">');
  });
</script>

use on

arun
  • 3,637
  • 3
  • 28
  • 54
1
<script type="text/javascript">
  $('.new').live('change',function() {
    $('.new').appendTo('#to').removeClass('new');
    $('#from').append('<input type="file" class="new">');
  });
</script>
coolguy
  • 7,728
  • 9
  • 43
  • 71
0

HIya 2 working demos for you : http://jsfiddle.net/UxyMw/ or http://jsfiddle.net/UxyMw/1/

both works fine:

code:

$('.new').on("change",function() {
    $('.new').appendTo('#to').removeClass('new');
    $('#from').append('<input type="file" class="new">');
  });​
Tats_innit
  • 33,645
  • 9
  • 68
  • 76
0

try this http://jsfiddle.net/UxyMw/3/

pranky64
  • 427
  • 3
  • 18