apend value to all rows

joe

by Joe

HTML

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<!-- validation cdn -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.2/css/bootstrapValidator.min.css">
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.19.0/jquery.validate.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.2/js/bootstrapValidator.min.js"></script>

<form id="contactForm">


<input type="button" class="add_Row adRow" id="add_Row" value="Add Row">
<table class="table table-bordered table-hover order-list" id="tab_logic" style="width:100% !important">
  <thead>
    <tr style="background-color: #680779; color: #fff;">
      <th class="text-center">
        select code*
      </th>
      <th class="text-center">
        description*
      </th>
      <th class="text-center">
        amount*
      </th>
      <th class="text-center">
        action*
      </th>
    </tr>
  </thead>
</table>

<!-- submit button -->

<div class="form-group col-4 vocSub" style="margin-bottom: 0px !important;">
  <div class="col-md-12 cashform_submit" id="">
    <input type="button" class="btn add-btn submit-btn load cashmainBtn" id="cashSub" value="Submit" />
  </div>
</div>

</form>

JavaScript

$(document).ready(function() {
  $("#ok_button").on("click", function() {

    $(".act").val($("#cash_text:first").val());
  });
  $("#add_Row").on("click", function() {

    var counter = 0;
    var idVal = $('#tab_logic tr:last').find('td:first').html();
    // alert(idVal);
    if (idVal === undefined) {
      counter = 0;
    } else {
      var matches = idVal.match(/\d+/g);
      // alert(matches);
      if (matches != null) {
        counter = Number(matches) + counter + 1;
      }
    }
    var newRow = $("<tr>");
    var cols = "";
    if ($('.price').length > 0) {
      var first_ele = document.querySelector('.price').value;
    } else {
      var first_ele = '';
    }
    cols += '<td><select class="form-control sel_sel status required" id="accountName' + counter + '" name="accountName" for="accountName" required><option value="">Choose an account</option><option value="1">code 1</option></select></td>';
    cols += '<td><input value="' + first_ele + '" type="text" class="form-control required price narr" name="narr" placeholder="Enter your text here" id="acc_narrat' + counter + '" data-toggle="modal" data-target="#narratModal"/></td>';
		
    cols += '<td><input type="number" class="form-control sumTot deb allignAmt" id="cashdeb' + counter + '" min="0" data-action="sumDebit" name="debit" placeholder="Debit amount" onkeypress="restrictMinus(event);" required/></td>';

    cols += '<td style="width: 11%;"><button type="button" class="adRow ibtnDel" style="width:30%;position: relative;right: 25%;">x</button></a></td>'

    newRow.append(cols);


    var defVal = $("select[name=acctname]").find(":selected").val();
    if (defVal) {
      $("select[name=accountName]").find(`option[value=${defVal}]`).hide();
    }
    $("table.order-list").append(newRow);
    setValCashVal('accountName'.concat(counter));
    bindScript();
    counter++;

  });
  $("table.order-list").on("click", ".ibtnDel", function(_event) {
    $(this).closest("tr").remove();
    if...