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,541
  • 28
  • 38
  • 38
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,667
  • 3
  • 29
  • 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,866
  • 9
  • 45
  • 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,991
  • 10
  • 71
  • 77
0

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

pranky64
  • 437
  • 3
  • 18