'Compare two values per row on multiple rows
I am stuck with the each function. Could someone please help me getting on the right track? Here is my code so far and an image to visualize what I am trying to achieve.
Thank you very much!
$('.ui-button').on('mouseenter', function () { // just for testing
var c = 1; // skip first row
var eventdate = $('.ui-sortable tr:nth-child(2) > td:nth-child(1) .InputfieldDatetimeDatepicker').attr('value');
var eventtime = $('.ui-sortable tr:nth-child(2) > td:nth-child(2) .uk-select option:selected').text();
$('.ui-sortable tr').each(function () {
c++;
var eventdate = $('.ui-sortable tr:nth-child(' + [c] + ') > td:nth-child(1) .InputfieldDatetimeDatepicker').attr('value');
var eventtime = $('.ui-sortable tr:nth-child(' + [c] + ') > td:nth-child(2) .uk-select option:selected').text();
if (eventdate === eventtime) { // ?
$(this).addClass('error');
}
console.log('eventdate: ' + eventdate + ', eventtime: ' + eventtime);
});
});
Solution 1:[1]
Fiddle code: When something is changed, then it is checked all rows!
$(function () {
$('.ui-sortable tr').on('change', function (e) {
$('.ui-sortable tr').each((i, tr)=>{
$(tr).attr('no', i);
$(tr).attr('class', '');
});
$('.ui-sortable tr').each((i, tr)=>{
let foundDuplicates = false;
let no = $(tr).attr('no');
let date = $(tr).children('td:nth-child(1)').children('input').val();
let time = $(tr).children('td:nth-child(2)').children('select').val();
$('.ui-sortable tr').each((i, tr_)=>{
let no_ = $(tr_).attr('no');
if(no === no_) return false;
let date_ = $(tr_).children('td:nth-child(1)').children('input').val();
let time_ = $(tr_).children('td:nth-child(2)').children('select').val();
if((date === date_) && (time === time_)){
$(tr).attr('class', 'error');
$(tr_).attr('class', 'error');
foundDuplicates = true;
}
});
if(foundDuplicates){
$(tr).attr('class', 'error');
}
});
});
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
