so I have this javascript function on my page which computes date. Now, I want to access the result thrown by the function in a php variable so that I can use that variable to insert value in a database. The function should be called on page load. I have been trying to get this done from past 4 hours but upto no solution, any suggestions and solutions are welcome.
My JS Code:-
<script language="JavaScript">
// function to calculate local time
// in a different city
// given the city's UTC offset
function calcTime(city, offset,selDate,selHours,selMinutes) {
//alert(selDate);
//alert(selHours);
//alert(selMinutes);
//alert(offset);
var str = selDate;
var res = str.split("/");
//07,26/2014
//0,1,2
var d = new Date(res[2], res[0], res[1], selHours, selMinutes, 0, 0);
// create Date object for current location
//alert(d);
// var d = new Date();
//alert(d);
// convert to msec
// add local time zone offset
// get UTC time in msec
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
// create new Date object for different city
// using supplied offset
nd = new Date(utc + (3600000*offset));
// return time as a string
return nd.toLocaleString();
}
function testTime(){
var selDate = document.getElementById("datepicker").value;
var selHours = document.getElementById("hours").value;
var selMinutes = document.getElementById("minutes").value;
var selTimeZone = document.getElementById("timezone").value;
alert(selDate);
alert(selHours);
alert(selMinutes);
alert(selTimeZone);
}
</script>
$.get( "ajax/dowork.php?selected=" + selDate );