Validation code for saving timetable entries

Posted by Aishu_Karthik under JavaScript on 4/12/2013 | Points: 10 | Views : 1221 | Status : [Member] | Replies : 2
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;
}
}
}

Thanks,
Aish P Karthi



Responses

Posted by: Learningtorise on: 5/7/2013 [Member] Starter | Points: 25

Up
0
Down
What Happened Pal ? R u still working at same COmpany ?

http://hashtagakash.wordpress.com/

Aishu_Karthik, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Aishu_Karthik on: 5/8/2013 [Member] Starter | Points: 25

Up
0
Down
Of course I was asked to. I found a solution myself.

Thanks,
Aish P Karthi

Aishu_Karthik, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response