Guest User

Untitled

a guest
Jul 9th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2. $(document).ready(function(){
  3.     var counter = 0;
  4.     var maxField = 10; //Input fields increment limitation
  5.     var addButton = $('.addField'); //Add button selector
  6.     var wrapper = $('.field_wrapper'); //Input field wrapper
  7.     var x = 1; //Initial field counter is 1
  8.     $(addButton).click(function(){ //Once add button is clicked
  9.         if(x < maxField){ //Check maximum number of input fields
  10.             x++; //Increment field counter
  11.              counter++;
  12.             $(wrapper).append('<tr><td><a href="javascript:void(0);" class="removeField" title="Remove Field"><i class="fa fa-times"></i><a></td><td><input id="field_'+counter+'" name="inv['+counter+'][name]" class="form-control input-sm" type="text" /></td><td><input id="field_'+counter+'" name="inv['+counter+'][description]" class="form-control input-sm" type="text" /></td><td><input id="field_'+counter+'" name="inv['+counter+'][qty]" class="form-control input-sm" type="text" /></td><td><div class="input-group"><span class="input-group-addon">$</span><input id="field_'+counter+'" name="inv['+counter+'][price]" class="form-control input-sm" type="text" /></td></div><td><div class="input-group"><span class="input-group-addon">$</span><input id="field_'+counter+'" name="inv['+counter+'][total]" class="form-control input-sm" /></td></div></tr>');
  13.             startStacktable();  //Recreates the mobile version of the table with the added <tr>
  14.         }else{
  15.             alert('Sorry, Only 10 fields per invoice.');
  16.         }
  17.        
  18.     });
  19.     $(wrapper).on('click', '.removeField', function(e){ //Once remove button is clicked
  20.         e.preventDefault();
  21.         $(this).closest('tr').remove(); //Remove field html
  22.         x--; //Decrement field counter
  23.     });
  24.     function startStacktable(){
  25.         $('table').stacktable();
  26.     }
  27.     startStacktable();  //Start Stacktable once the page is loaded
  28. });
  29. </script>
Add Comment
Please, Sign In to add comment