Need to Validate TO date is greater than FROM date

I have this function that I can call via a button, but I would like to implement this as a cell validation when the date is entered into the TO column of my grid.

function checkDates() {
var confirm = true;
mygridDates.forEachRow(function (id) {
var val1 = mygridDates.cells(id, 1).getValue();
var val2 = mygridDates.cells(id, 2).getValue();
if (val1 >= val2)
confirm = false;

What I would like to do:
//Dates Grid
mygridDates = new dhtmlXGridObject(‘mygrid_Dates’);
mygridDates.enableValidation(true, true, true);
mygridDates.attachEvent(“onValidationError”, function (id, ind, value) {
mygridDates.setCellTextStyle(id, ind, “font-weight:bold;”);
document.getElementById(‘message’).innerHTML = “Error at cell (” + id + “,” + ind + "), value must " + (ind == 0 ? “not be empty” : “be a valid date”);
return false;
mygridDates.attachEvent(“onValidationCorrect”, function (id, ind, value) {
mygridDates.setCellTextStyle(id, ind, “”);
document.getElementById(‘message’).innerHTML = “”;
return false;

Any help would be appreciated.

Can anyone help here?
:question: :question: :question: :question: :question: :question: :question: :question: :question:

Try to use try…catch block to view where your code is corrupted.

Your function must return -1, 0 or 1

What I am really trying to get at is a way to run the validation when the second column in the row changes. I have found ways to validate that the cell is not blank, but I need to validate that the cell is greater than the previous cell and if not indicate that in the grid.

I do appreciate the help on the coding flaws that I have.

Perhaps you can use a “Bubblesort” like this:

for (var x= 0; x < mygrid.getRowsNum(); x++)
  for (y = mygrid.getRowsNum() - 1; y > x; y--)
      var xRowId = mygrid.getRowId(x);
      var yRowId = mygrid.getRowId(y);
  // Compare mygrid.cells(xRowId,2).getValue() with mygrid.cells(yRowId,2)


// Compare mygrid.cells(xRowId,2).getValue() with mygrid.cells(yRowId,2);

F***, correction 2 (how can i edit my post here?):

// Compare mygrid.cells(xRowId,2).getValue() with mygrid.cells(yRowId,2).getValue()