Bruce
Bruce

Reputation: 181

Dynamically jQuery use .append() add inputs , but posting form is not append data

I use appends add inputs , but post form is not add inputs data.

where wrong with my code?

HTML code

<form class="form_a" action="test_a.php" method="POST" >
<div class="language">
    <div class="append">

    </div>
    <button type="button" class="add">add Button</button>

    <input type="submit" value="submit">
    </div>
</form>

Javascript code

$('.language .add').click(function(){
    $('.language .append').append(
        '<input name="language[]" class="form-control" value="test">'
    );
});

PHP code

<?php
  print_r($_POST['language']);
?>

Upvotes: 0

Views: 231

Answers (1)

Webomatik
Webomatik

Reputation: 836

If you change

</buttond>

for

</button>

, the form works just fine. Wrapping your javascript in a jQuery call helps:

$(document).ready(function(e) {
    $('.language .add').click(function(){
        $('.language .append').append($('<input name="language[]" class="form-control" value="test">'));
    });
});

Upvotes: 1

Related Questions