Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two text boxes that can be duplicated by clicking on add button using following code
HTML
<table  id="tbl1"  class="form-group">
           <tr><td class="col-sm-1">Code:</td><td class="col-sm-1"><input type="number" data-type="number" id="Code"/></td><td class="col-sm-1">Fine:</td><td><input type="text" id="Fine" placeholder="Fine"/></td> <td> <a href="java<!-- no -->script:void(0);" id='anc_add' class="btn btn-green">Add Code</a></td>
      <td><a href="java<!-- no -->script:void(0);" id='anc_rem' class="btn btn-red ">Remove Code</a></td></tr>
           </table>

jquery code is
JavaScript
<script>
           $(document).ready(function () {
               var cnt = 2;
               $("#anc_add").click(function () {
                   $('#tbl1 tr').last().after('<tr><td class="col-sm-1"> Code:' + cnt + '</td><td  class="col-sm-1"><input type="number"  id="Code' + cnt + '" placeholder="Code"></td><td class="col-sm-1"> Fine:' + cnt + '</td><td><input type="text" id="Fine' + cnt + '" readonly="readonly" placeholder="Fine"></td></tr>');
                   cnt++;
               });

               $("#anc_rem").click(function () {
                   if ($('#tbl1 tr').size() > 1) {
                       $('#tbl1 tr:last-child').remove();
                   }
                   else {
                       alert('One row should be present in table');
                   }
               });
               var getval = $('input[data-type="number"]').val;
           });
</script>

i want to get code and fine value from each textbox which may be one two so on and save them in a table
which have column as
SQL
id Code  Fine
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900