Hi all,
My requirement is simple.
* I have a grid in my page with 3 columns, From Time and To Time.
* When I click a button above the grid, I have got to open a modal popup window.
* In the popup, I have 4 dropdowns - From Hours, From Minutes, To Hours and To Minutes.
* Consider, I select 08(From Hours), 40(From Minutes) and 09(To Hours), 20(To Minutes.)
* I click the add button. The popup closes, and the above selected values are populated in the grid as
FromTime ToTime
08-40 09-20
* Now, when I want to enter another set of values, I have to validate as follows.
The new time should be more than the ones already present in the grid. (The 2nd set of data can start with 09-20 to .. though.)
* Example, if I choose times 09-00 to 09-30, I should get an alert and the popup should stay as it is. When I enter correct values(say 09-20 to 10-00) the popup should close and the values should be added to the grid.
Can someone provide me a solution for this? It is urgent, my job is at stake ..
P.S. My code, which doesn't work the way I want it to.
function validateTime() {
var table = document.getElementById('<%=gvTimeSlots.ClientID%>');
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];
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);
if(('<%= cboFromTimeHours.SelectedValue%>') >= 0 && (('<%= cboFromTimeHours.SelectedValue%>')) < 10){
newFromHour = "0" + ('<%= cboFromTimeHours.SelectedValue%>');
}
else{
newFromHour = ('<%= cboFromTimeHours.SelectedValue%>');
}
newFromMin = ('<%= cboFromTimeMins.SelectedValue%>');
newFromTime = parseInt(newFromHour * 60) + parseInt(newFromMin);
if (('<%= cboToTimeHours.SelectedValue%>') >= 0 && (('<%= cboToTimeHours.SelectedValue%>')) < 10) {
newToHour = "0" + ('<%= cboToTimeHours.SelectedValue%>');
}
else {
newToHour = ('<%= cboToTimeHours.SelectedValue%>');
}
newToMin = ('<%= cboToTimeMins.SelectedValue%>');
newToTime = parseInt(newToHour * 60) + parseInt(newToMin);
if (newFromHour < oldFromHour || newFromHour < oldToHour){
alert("do not add.");
return false;
}
}
}