how to join two table in codeigniter easily[updated] | ci_model | ci_controller | codeigniter 3 -datainflow
Hello peoples,
Welcome to my new programming article on how to add and delete table row dynamically in jquery. So let’s get started.
First of all, you need a table and the jquery CDN inside your page. and make a table like this:
<!DOCTYPE html> <html lang="en"> <head> <style> .th{ text-align: center; } </style> <title>Add And Delete Row</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="jumbotron text-center"> <h2>Add and delete row dynamically</h2> </div> <div class="container"> <div class="row" style="margin-bottom: 10px; margin-left: 10px;"> <button type="button" class="btn btn-primary" id="RowCreateBtn">Add new</button> <button type="button" class="btn btn-danger" id="RowDeleteBtn">Delete</button> </div> <div class="row"> <div class="col-sm-4 col-md-12"> <table class="table table-bordered" id="dynamicTable"> <thead> <tr> <th>#</th> <th class="th">Name</th> <th class="th">Email</th> <th class="th">Contact</th> </tr> </thead> <tbody> <tr> <td><input type="checkbox" name="Chk"></td> <td><input type="text" class="form-control" name="name[]"></td> <td><input type="text" class="form-control" name="email[]"></td> <td><input type="text" class="form-control" name="contact[]"></td> </tr> </tbody> </table> </div> </div> </div> </body> </html>
Now take a script just after body tag ended and implement the below codes:
<script> $('#RowCreateBtn').click(function(){ var row = '<tr><td><input type="checkbox" name="Chk"></td><td><input type="text" name="name[]" class="form-control"></td><td><input type="text" name="email[]" class="form-control"></td><td><input type="text" name="contact[]" class="form-control"></td></tr>'; $('#dynamicTable tbody').append(row); }); $('#RowDeleteBtn').click(function(){ $("table tbody").find('input[name="Chk"]').each(function(){ if($(this).is(":checked")){ $(this).parents("tr").remove(); } }); }); </script>
Related posts
Super code simple, j’aimerai savoir est-il possible de faire le calcul de deux inputs sur chaque ligne, si oui comment procéder? merci, Bonne journée