vendredi 7 août 2020

If condition is not working for all td values?

i am working with html table, when i check the checkbox i want to compare td values in a every tr, this condition is working fine for 1st tr from 2nd tr the condition is not working.
HTML Code -

<form role="form" name="conForm" id="conForm">
                    <span id="error" class="text-danger"></span>
                    <div class="table-responsive">
                        <table id="myPTable" class="table table-xss table-hover table-bordered">
                        <thead>
                        <tr>
                        <th><input class="checkall" type="checkbox" name="productcheckbox"> All</</th>
                        <th class="control-label paddingtop">SI No</th>
                        <th class="control-label paddingtop">Products</th>
                        <th class="control-label paddingtop">Pending Qty</th>
                        <th class="control-label paddingtop">Quantity</th>
                        <th class="control-label paddingtop">Amount</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                        <td><input class="checkbox checkproduct" type="checkbox" name="check"></td>
                        <td>1</td>
                        <td>HMIS HMIS HMIS HMIS</td>
                        <td class="availableQty">10</td>
                        <td><input  type="number" name="select[]" class="enterQty" value="10" style="width:50px;"></td>
                        <td>3000</td>
                        </tr>
                        <tr>
                        <td><input class="checkbox checkproduct" type="checkbox" name="check"></td>
                        <td>2</td>
                        <td>ERP</td>
                        <td class="availableQty">1</td>
                        <td><input  type="number" name="select[]" class="enterQty" value="1" style="width:50px;" ></td>
                        <td>9000</td>
                        </tr>
                        <tr>
                        <td><input class="checkbox checkproduct" type="checkbox" name="check"></td>
                        <td>3</td>
                        <td>Inventory</td>
                        <td class="availableQty">10</td>
                        <td><input  type="number" name="select[]" class="enterQty" value="10" style="width:50px;"></td>
                        <td>13000</td>
                        </tr>
                        <tr><td><button class="btn-info">Save</button></td></tr>
                        </tbody>
            </table>
            </form>

Here is the jquery code -

$(".btn-info").on("click",function(){
               
                var check = $('.checkproduct');              
                  if(check.is(':checked')){
                      
                      var pending="";
                      $('#myPTable tr').each(function() {
                        pending =+ $(this).find(".availableQty").html();    
                        console.log(pending);
                      });
                
                      var enterqty ="";
                      $('#myPTable tr').each(function() {
                        enterqty =+ $(this).find(".enterQty").val();
                        console.log(enterqty);
                      });

                      if(enterqty > pending){
                          $("#error").html("<p>Quantity must be less than or equal to Pending Qty</p>");                          
                      }else if(enterqty== 0){
                          $("#error").html("<p>you have checked the product please enter quantity</p>");
                        }
                              else{                          
                        var checked = $('.checkproduct:checked').size();
                      }

the jquery what i wrote is working for only first row, but it need to be work for every work which will be checked.now only you guys can help me, thanks in advance.

Aucun commentaire:

Enregistrer un commentaire