Table - Next Row

Hello,

I'm writing some code to pop up an error message when the drop down box has a specific selection and the Input box is empty. The code works great on the first row but when I goto the second row the error message doesnt work. It only seems to work on the first row. I maight have 2,3,4 etc rows where I want an error message to pop up if no value is in the input box. What am I missing, I thought in for the for statement the i++ moves the loop to next row.
This is my code. Any help would be great. Thanks

(function() {
'use strict';

var DCDD = 'drum_needed';
var DC = 'drum_input';

var events = ['app.record.create.submit',
'app.record.create.change',
'app.record.edit.change',
'app.record.edit.submit',
'app.record.index.edit.submit'];

kintone.events.on(events, function(event) {
var record = event.record;
var error_message = "OTHER WAS SELECTED! YOU MUST ENTER INFO INTO THE INPUT BOX UNDER < 3.DRUM > TAB"
var error_message_color = "COLOR WAS SELECTED! YOU MUST ENTER INFO INTO THE INPUT BOX UNDER < 3.DRUM > TAB"
var tablesrows = record.drum_use_table.value;

for (var i = 0; i < tablesrows.length; i++) {
  var row = tablesrows[i].value;
  var dcolor = row[DCDD].value;
  var dcom = row[DC].value;
  
  
  if(!dcom && dcolor === "OTHER") {
  
   
    event.error = error_message;
  

}
  if(!dcom && dcolor === "Color") {
    event.error = error_message_color;
}
return event;

}

});
})();

Hello @dpoetsch
The issue in your code is that the return event; statement is inside the loop, which causes the function to exit after checking only the first row. To fix this, move the return event; statement outside of the loop.

Here's the revised script:

(function() {
    'use strict';

    var DCDD = 'drum_needed';
    var DC = 'drum_input';

    var events = ['app.record.create.submit',
        'app.record.create.change',
        'app.record.edit.change',
        'app.record.edit.submit',
        'app.record.index.edit.submit'
    ];

    kintone.events.on(events, function(event) {
        var record = event.record;
        var error_message = "OTHER WAS SELECTED! YOU MUST ENTER INFO INTO THE INPUT BOX UNDER < 3.DRUM > TAB";
        var error_message_color = "COLOR WAS SELECTED! YOU MUST ENTER INFO INTO THE INPUT BOX UNDER < 3.DRUM > TAB";
        var tableRows = record.drum_use_table.value;

        for (var i = 0; i < tableRows.length; i++) {
            var row = tableRows[i].value;
            var dcolor = row[DCDD].value;
            var dcom = row[DC].value;

            if (!dcom && dcolor === "OTHER") {
                event.error = error_message;
                return event;
            }
            if (!dcom && dcolor === "Color") {
                event.error = error_message_color;
                return event;
            }
        }
        return event;
    });
})();

Thank you again @Chris for explaining the return event and showing me where the corrections were needed. Works great.