I have set session variable 'activeAcademicyearStartsOn' at the time of login.
If we var_dump() the session variable in view.php, the output is like
object(stdClass)#11 (1) { ["$date"]=> object(stdClass)#12 (1) { ["$numberLong"]=> string(13) "1546297200000" } }
Now in view.php file, I am trying to get session variable in a javascript code inside javascript tag like
$("#session_start_date").val(getDateString('<?php echo $_SESSION['activeAcademicyearStartsOn'] ?>'));
All the Javascript stops working.
<script type="..">
...
...
$(document).ready(function(){
...
$("#session_start_date").val(getDateString('<?php echo $_SESSION['activeAcademicyearStartsOn'] ?>'));
...
});
function getDateString(str)
{
if (str == '')
return;
var dateObj = new Date(str.$date.$numberLong - 1000);
var month = dateObj.getMonth() + 1; //months from 1-12
var day = dateObj.getDate();
var year = dateObj.getFullYear();
return (month + "/" + day + "/" + year);
}
</script>
In order to test, if I put another session variable it works fine like
$("#session_start_date").val('<?php echo $_SESSION['uid'] ?>');
Any help appreciated.
Seems to me your echoing an object in php, into a quoted string in javascript, and your using it as a object in your function.
If you take your php object, and convert it into a javascript object it should work better i think.
You will need to do 2 things
(This entire peice of code is 1 single line.)
inside the getDateString() function.