Dinamic Form JQuery

Dinamic Form JQuery

Dinamic Form JQuery

Easily use Dynamic Form JQuery for your website.

Dynamic input field allows providing multiple values in a form. multi-input is a jQuery form builder/manipulation plugin which makes it possible to dynamically add and/remove form fields by clicking on Plus and Minus buttons. This tutorial will show you how to dynamically add form elements to a form using jQuery.

 

HTML Code:

==============================

  1. <!doctype html>
  2. <html lang="en">
  3.   <head>
  4.         <!--  ......meta tags Required......... all source code www.onlylearn24.com -->
  5.         <meta charset="utf-8">
  6.         <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7.         <!-- Bootstrap CSS ......... all source code www.onlylearn24.com -->
  8.         <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  9.         <title>Dinamic Form JQuery!</title>
  10.   </head>
  11.   <body>
  12.         <div class="container">
  13.           <br>
  14.           <h3 align="center"> Dinamic input Name Name[] Form </h3>
  15.           <div class="form-group">
  16.              <form action="" method="" name="add-name" id="add-name">
  17.                <table class="table table-bordered" id="dinamic_field">
  18.                  <tr>
  19.                    <td><input type="text" name="name[]" id="name" class="form-control" placeholder="Enter Value"></td>
  20.                    <td><div class="btn btn-success" name="add" id="add">Add</div></td>
  21.                  </tr>
  22.                
  23.                </table>
  24.                  <input type="button" name="submit" id="submit" value="submit" />
  25.              </form>
  26.           </div>
  27.         </div>
  28.   
  29.         <!--  then Bootstrap JS, jQuery first, then Popper.js all source code www.onlylearn24.com -->
  30.         <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  31.         <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  32.         <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  33.         
  34.   </body>
  35. </html>

 

jquery code:

========================

  1. <script>
  2.       //........ all source code www.onlylearn24.com
  3.       var ic = 1;
  4.       $('#add').click(function(){
  5.         ic ++;
  6.        $('#dinamic_field').append('<tr id="row'+ic+'"><td><input type="text" name="name[]" placeholder="Enter Value" class="form-control"></td><td><div class="btn btn-danger btn_remove" name="remove" id="'+ic+'">Close</div></td></td></tr>')
  7.       });
  8.       //........... all source code www.onlylearn24.com
  9.       $(document).on('click','.btn_remove', function(){
  10.         var button_x_id = $(this).attr("id");
  11.         console.log(button_x_id);
  12.         $('#row'+button_x_id+'').remove();
  13.         
  14.       });
  15.       //....... all source code www.onlylearn24.com
  16.       $('#submit').click(function(e){
  17.         e.preventDefault();
  18.         var data_d = JSON.stringify( $("#add-name").serializeArray() )
  19.         console.log(data_d);
  20.       });
  21. </script>

 

Output: 

======================================

 

Thank You..........................