Please check the code

Posted by Rrana under JavaScript on 9/22/2011 | Points: 10 | Views : 1257 | Status : [Member] | Replies : 2
Please check this code and tell me what is the problem


function TimeValidation()
{
var str1 = document.getElementById("<%=hdn1.ClientID%>").value;
var str2 = document.getElementById("<%=hdn2.ClientID%>").value;
var Time_array=str1.split("/");
var mon1 = parseInt(Time_array[0]);
var dt1= parseInt(Time_array[1]);
var yr1 = parseInt(Time_array[2].substring(0,4),10);*********Error
var Time_array1=str2.split("/");
var mon2 = parseInt(Time_array1[0]);
var dt2= parseInt(Time_array1[1]);
var yr2 = parseInt(Time_array1[2].substring(0,4),10);*********Error

}



Error as Microsoft JScript runtime error: '2' is null or not an object

Sucharitha Goud
Bank Of America..



Responses

Posted by: Vishvvas on: 9/22/2011 [Member] [MVP] HonoraryPlatinum | Points: 25

Up
0
Down
Looks like the element having name consisting of "2" is not found on the page. Please check the name and ID for the elements.
Hope this helps.

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

Posted by: Rrana on: 9/23/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Vishvvas,

Thanks for your response,

Actually, i dodn't know java script, can you please correct this function


This is my function, actually i don't know javascript, can you please correct this function.

function TimeValidation()
{
var str1 = document.getElementById("<%=hdn1.ClientID%>").value;
var str2 = document.getElementById("<%=hdn2.ClientID%>").value;
var Time_array=str1.split("/");
var mon1 = parseInt(Time_array[0]);
var dt1= parseInt(Time_array[1]);
var yr1 = parseInt(Time_array[2].substring(0,4),10);
var Time_array1=str2.split("/");
var mon2 = parseInt(Time_array1[0]);
var dt2= parseInt(Time_array1[1]);
var yr2 = parseInt(Time_array1[2].substring(0,4),10);
var starttime = new Date(yr1, mon1-1, dt1);
var endtime = new Date(yr2, mon2-1, dt2);
var StartHr=document.getElementById("<%=ddStartHr.ClientID%>").value;
var EndHr=document.getElementById("<%=ddEndHr.ClientID%>").value;
var StartMin=document.getElementById("<%=ddStartMin.ClientID%>").value;
var EndMin=document.getElementById("<%=ddEndmin.ClientID%>").value;


if (starttime > endtime)
{
alert('End date should not be less than start date');
return false;
}
else if(str1 == str2)
{
if(StartHr-EndHr < 0)
{
return true;
}
else if(StartHr-EndHr > 0)
{
alert('End time cannot be less than Start time !!');
return false;
}
else if(StartHr-EndHr == 0)
{
if(StartMin - EndMin > 0)
{
alert('End time cannot be less than start !!');
return false;
}
if(StartMin - EndMin < 0)
{
return true;
}
if(StartMin - EndMin == 0)
{
alert('Start time and End Time cannot be same !!');
return false;
}
}
}

else if(starttime < endtime)
{
if(StartHr-EndHr == 0)
{
if(StartMin - EndMin < 0)
{
return true;
}
if(StartMin - EndMin == 0)
{
alert('Start time and End Time cannot be same !!');
return false;
}
if(StartMin - EndMin > 0)
{
alert('Start time cannot be greater than end time !!');
return false;
}
}


}

}




Sucharitha Goud
Bank Of America..

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

Login to post response