Hello everybody
I have some issues in my program.
Let me explain my requirement briefly, i am using php, mysql, javascript and ajax for my application.
when my application opens means if user logs into application automatically a pop up window should come, means i don't want for every time that should open, For specific condition only pop up window will open.
Let me explain that condition i have table called interview and field called as Interview_date and time. If interview_date is current date and interview time difference with the current time is less than 2 hours or greater than 2 hours. Then only pop window should open.
Through XmlHttp request i can able to fetch interview date and time from database of that particular user (means who logs in), through xmlHttpr.responseText i can able to catch interview date and time.
but i can't able to return I_date and I_time from outside of function.
below i am showing my source code
[HTML]<html>
<head>
<script type='text/javascript'>
function cal_time()
{
var logged_in_user='{$_SESSION[valid_user]}';
date1 = new Date();
date2 = new Date();
diff = new Date();
var theyear=date1.getFullYear()
var themonth=date1.getMonth()+1
var thetoday=date1.getDate()
var curr_time = date1.getTime();
var curr_hour = date1.getHours();
var curr_min = date1.getMinutes();
if(curr_hour >= 12)
{
if(curr_hour == \"12\")
{
meridian = \"PM\";
} else {
curr_hour = curr_hour - 12;
meridian = \"PM\";
}
}else {
meridian = \"AM\";
}
var tot_time = themonth + '/' + thetoday + '/' + theyear + ' ' + curr_hour + ':' + curr_min + ' ' + meridian;
var xmlHttpr;
xmlHttpr=GetXmlHttpObject()
if (xmlHttpr==null)
{
alert (\"Browser does not support HTTP Request\")
return
}
var url=\"http://localhost/recruitmentsolution/auto.php\";
url=url+\"?c=\"+logged_in_user;
xmlHttpr.onreadystatechange=getusername;
xmlHttpr.open(\"GET\",url,true)
xmlHttpr.send(null)
function getusername()
{
if (xmlHttpr.readyState==4 || xmlHttpr.readyState==\"complete\")
{
usernamestring=xmlHttpr.responseText
userarr = usernamestring.split(\"!\");
nm = userarr[0];
var nm2 = userarr[1];
var nm3 = nm2.split(\"-\");
tot = nm3[1] + '/' + nm3[2] + '/' + nm3[0];
finall = tot + ' ' + nm;
return(finall);
}
}
function GetXmlHttpObject()
{
var xmlHttpr=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttpr=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttpr=new ActiveXObject(\"Msxml2.XMLHTTP\");
}
catch (e)
{
xmlHttpr=new ActiveXObject(\"Microsoft.XMLHTTP\");
}
}
return xmlHttpr;
}
var ttemp_tot_time = getusername();
var t_tot_time = ttemp_tot_time;
var a = tot_time;
var b = t_tot_time;
date1temp = new Date(a);
date2temp = new Date(b);
date1.setTime(date1temp.getTime());
date2.setTime(date2temp.getTime());
// sets difference date to difference of first date and second date
diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
timediff = diff.getTime();
weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
timediff -= weeks * (1000 * 60 * 60 * 24 * 7);
days = Math.floor(timediff / (1000 * 60 * 60 * 24));
timediff -= days * (1000 * 60 * 60 * 24);
hours = Math.floor(timediff / (1000 * 60 * 60));
timediff -= hours * (1000 * 60 * 60);
mins = Math.floor(timediff / (1000 * 60));
timediff -= mins * (1000 * 60);
secs = Math.floor(timediff / 1000);
timediff -= secs * 1000;
if(days < 1 && t_tot_time != 'undefined')
{
if((hours == 1 && (mins == 58 || mins ==59) ) ||(hours == 2 && (mins == 0 || mins == 1)))
{
popWindow();
var howLong = 4000;
t = null;
t = setTimeout(\"newWindow.close()\",howLong);
} else {
return false;
}
}
}
</head>
<body onload='cal_time();'>
</body>
</html>[/HTML]
I am calling getusername() function to get Interview_Date and Interview_Time values and that will store into ttemp_tot_time variable. But the function getusername() is not returning any value its returning a null value. If i alert the value of variable finall it's showing the value.
please help me in this part to get date and time value, so that i can calculate the difference and i can open pop up window.
i am waiting for your reply.
Thankyou