Wednesday, July 29, 2015

How to validate table column values as Row level

function ValidateTableTDInputValues() {
$('input').removeClass('error');
       $('span.mandatory').remove();
       var res = true;
       this.$('.ClassName1, .ClassName2').each(function () {
       var value = '';
       value = $(this).val();
       var tableRow = $(this).parent().parent();
       if (value != "") {
       var txtBoxOneInput = tableRow.find("td:nth-child(1) input[type=text]");
       var txtBoxOneValue = txtBoxOneInput.val();
       var txtBoxTwoInput = tableRow.find("td:nth-child(2) input[type=text]");
var txtBoxTwoValue = txtBoxTwoInput.val();
       var txtBoxThreeInput = tableRow.find("td:nth-child(3) input[type=text]");
       var txtBoxThreeValue = txtBoxThreeInput.val();
       var txtBoxFourInput = tableRow.find("td:nth-child(4) input[type=text]");
       var txtBoxFourValue = txtBoxFourInput.val();

       if (!$(txtBoxOneInput).hasClass('error') && $.trim(txtBoxOneValue) == '') {
       $(txtBoxOneInput).addClass('error').after('<span class="mandatory">*</span>');
res = false;
       }
      
if (!$(txtBoxTwoInput).hasClass('error') && $.trim(txtBoxTwoValue) == '') {
       $(txtBoxTwoInput).addClass('error').after('<span class="mandatory">*</span>');
res = false;
}
      
if (!$(txtBoxThreeInput).hasClass('error') && $.trim(txtBoxThreeValue) == '') {
       $(txtBoxThreeInput).addClass('error').after('<span class="mandatory">*</span>');
res = false;
       }
if (!$(txtBoxFourInput).hasClass('error') && $.trim(txtBoxFourValue) == '') {
       $(txtBoxFourInput).addClass('error').after('<span class="mandatory">*</span>');
res = false;
}
    }
});
 if (res) { return true; } else { return false; }
}

No comments:

Post a Comment