jquery - Validation for all <tr> by checkbox not working -


i have table checkbox in first <td>, want check <tr> check boxes checked.

<table> <tr>     <th style="width: 5%;">select</th>     <th style="width: 5%;">id</th>     <th style="width: 10%;">name</th>     <th style="width: 5%;">order</th>     <th style="width: 5%;">price</th>  </tr> <c:foreach var="pack" items="${packlist}" varstatus="rowcounter">     <tr class="allpackclass">         <td class="selective_catcreation"><input type="checkbox" name="packidcatcreate" value="${pack.packid}"></td>         <td>${pack.packid}</td>         <td>${pack.name}</td>         <td><input type="text" name="packdisorder" disabled="disabled" style="width: 20px;" value=""></td>         <td><input type="text" name="packprice" disabled="disabled" style="width: 20px;" value=""></td>     </tr> </c:foreach> </table> 

validation -->

$("tr.allpackclass").each(function() {         if($(this).is(":checked")== true){             if($(this).closest('tr').find('input:text').val() == ""){                 $("#validationdiv_").html("<span style='font-size:12px;color:red;'>fileds missing</span>");                 return false;             }         }     }); 

please help, doing wrong?

your if condition not working because inside each loop this referencing tr element, not checkbox inside it

change tr filter fetches trs checked check boxes , remove if condition inside it

$("tr.allpackclass").has('input[name="packidcatcreate"]:checked').each(function() { 

ex

$("tr.allpackclass").has('input[name="packidcatcreate"]:checked').each(function() {     var $emtpy = $(this).find('input:text').filter(function() {                 return $.trim(this.value).length == 0;             });     if ($emtpy.length) {         $("#validationdiv_")                 .html("<span style='font-size:12px;color:red;'>fileds missing</span>");         return false;     } }); 

update:

var valid = $("tr.allpackclass").has('input[name="packidcatcreate"]:checked').filter(function() {     return $(this).find('input:text').filter(function() {         return $.trim(this.value).length == 0;     }).length > 0; }).length == 0; if (!valid) {     $("#validationdiv_").html("<span style='font-size:12px;color:red;'>fileds missing</span>");     return false; }} 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -