I have a gridview with information like Period, FromTime and ToTime. In each row, I have an Edit(linkbutton). On clicking Edit, I open a popup window. The popup has 2 dropdowns - FromTime and ToTime, 1 button. When I click the button, the times get added to the grid. I need a validation like

If I enter Period 1 8.30 to 9.00, Period 2 9.00 to 9.30, then the ones which I save after this should be beyond 9.30 only.
Following is the code I have tried, but it doesn't work when I try to edit the data.

function validateTime(source, arguments) {

        var table = document.getElementById('<%= gvTimeSlots.ClientID%>');

        var RI = document.getElementById('<%= HiddenRowIndex.ClientID%>').value;
        var gvRowCount = table.rows.length;
        var Row;
        var oldFromTime, oldToTime;
        var oldFT, oldTT;
        var oldFromHour, oldFromMin, oldToHour, oldToMin;
        var newFromHour, newFromMin, newToHour, newToMin;
        var newFromTime, newToTime;
        for (var i = 1; i < table.rows.length; i++) {
            Row = table.rows[i];

            //if (mode > 0) {
                if (RI != i - 1) {
                    oldFT = new Array();
                    oldTT = new Array();
                    oldFromTime = Row.cells[4].innerText;
                    oldToTime = Row.cells[5].innerText;
                    oldFT = oldFromTime.split("-");
                    oldTT = oldToTime.split("-");
                    oldFromHour = oldFT[0];
                    oldFromMin = oldFT[1];
                    oldToHour = oldTT[0];
                    oldToMin = oldTT[1];

                    oldFromTime = parseInt(oldFromHour * 60) + parseInt(oldFromMin);
                    oldToTime = parseInt(oldToHour * 60) + parseInt(oldToMin);

                    newFromHour = document.getElementById('<%= cboFromTimeHours.ClientID%>');
                    newFromMin = document.getElementById('<%= cboFromTimeMins.ClientID%>');

                    newFromTime = parseInt(newFromHour.value * 60) + parseInt(newFromMin.value);

                    newToHour = document.getElementById('<%= cboToTimeHours.ClientID%>');
                    newToMin = document.getElementById('<%= cboToTimeMins.ClientID%>');
                    newToTime = parseInt(newToHour.value * 60) + parseInt(newToMin.value);

                    //if ((oldFromTime >= newFromTime) && (oldToTime > newToTime) && (newToTime <= newFromTime)) {
                    if ((oldFromTime <= newFromTime) && (oldToTime <= newToTime) && (oldFromTime <= newToTime) && (oldToTime <= newFromTime)) {
                        arguments.IsValid = true;

                    }
                    else {
                        arguments.IsValid = false;

                    }
                }

            //}
        }
    }

The validation doesn't work when I edit. How do I fix this?

That is not vb code, but you posted this in the vb.net forum. I'm moving it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.