Dynamically Add / Remove input fields in PHP with Jquery Ajax

36
13



Add or Remove input fields dynamically with Ajax JQuery. Add Input Field using Jquery. How to Add / Remove textbox dynamically with Jquery. Javascript add input fields dynamically. Dynamically add input fields and submit to database with Jquery and PHP. Add Field dynamically to form in jquery and php. Dynamically Add form fields PHP. Source Code –

Nguồn:https://wijstaanvooronzegrondrechten.org/

36 COMMENTS

  1. Hi,
    First thanks for the explanation, your tutorial work well, but there is one little bug, the process of adding or removing inputs doesn't respect the order of the id.
    for instance : let's assume you add an input that has id=5, for some reason you remove it and you want to add it again, the new input got the id=6 instead of 5. to fix that just add i=i-1 at the end of the code
    $(document).on('click', '.btn_remove', function() {
    var button_id = $(this).attr("id");
    $('#row'+button_id+'').remove();
    i = i-1;
    });

  2. hello, how to insert multiple data and i dont see the code when you insert sql code, please i want to see for more comprehension.

  3. thanks webslesson , i can try lot of think to dynamically add input field and save its data on database,but i can only store only one value ,but your tutorials help me lot,thanks once again

  4. if i try to enter a name of the first input field without pressing the Add More button, I get the message Please Enter Name. Similarly, if I remove all the extra input fields and try to submit a name via the original input field only, I get the same message.

    If I use multiple input fields, all the names are entered correctly, including from the original input field.

    Can someone please help?

  5. It doesnt work for me..
    Code :

    <div class='row' id='dynamic_field'>
    <div class='three columns innerpadding offsetTwo'>
    <label>Team Members
    <input type='text' name='team_members' class="name_list" placeholder='Enter the username of your team members'>
    </label>
    </div>
    <div class='two columns innerpadding' style='margin-top: 42px;'>
    <a class='button green' id='add' name='add'><i class='fas fa-plus'></i>Add More</a>
    </div>
    </div>

    <script>
    $(document).ready(function() {
    var i = 1;
    $("#add").click(function() {
    i++;
    $("#dynamic_field").append("<div class='row' id='row"+i+"'> <div class='three columns innerpadding offsetTwo'><input type='text' name='name[]' class='name_list' placeholder='Enter the username of your team members'></div><div class='two columns innerpadding' style='margin-top: 42px;'><a class='button red btn_remove' id='"+i+"' name='remove'><i class='fas fa-times'></i></a></div><input type='button' name='submit' id='submit' value='submit'></div>");
    )};
    $(document).on("click", ".btn_remove", function() {
    var button_id = $(this).attr("#id");
    $("#row"+button_id+"").remove();
    )};
    )}:

LEAVE A REPLY

Please enter your comment!
Please enter your name here