abazoskib Posted August 17, 2009 Share Posted August 17, 2009 <script type="text/javascript">setTimeout(extendSession, <?php echo $timeLeft; ?>, "<?php echo $id; ?>");</script> i keep getting 'undefined' as the value for where $id should go. echo $id; returns the correct value. what am i doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/170603-solved-php-var-into-js-headache/ Share on other sites More sharing options...
RichardRotterdam Posted August 17, 2009 Share Posted August 17, 2009 I suggest you look in your browser source and see how the javascript gets generated. What does that look like in plain javascript? Quote Link to comment https://forums.phpfreaks.com/topic/170603-solved-php-var-into-js-headache/#findComment-899864 Share on other sites More sharing options...
abazoskib Posted August 17, 2009 Author Share Posted August 17, 2009 if i echo the statement without it being run as javascript it loooks like it should run. here is the echo <script type="text/javascript">setTimeout(extendSession, 10798000, "d8aee766_addf_4cc5_b51c_17294215f928");</script> extendSession runs after the specified timeout perfectly, however the parameter does not get passed as its value, it gets passed as 'undefined' Quote Link to comment https://forums.phpfreaks.com/topic/170603-solved-php-var-into-js-headache/#findComment-900007 Share on other sites More sharing options...
RichardRotterdam Posted August 17, 2009 Share Posted August 17, 2009 A couple of questions for you regarding the following code <script type="text/javascript"> setTimeout( extendSession, 10798000, "d8aee766_addf_4cc5_b51c_17294215f928" ); </script> the third arguement is optional and the values allowed are (JScript | VBScript | JavaScript) That third value does not make sense here. What does the extendSession function look like? maybe your javascript should look like: <script type="text/javascript"> setTimeout('extendSession( "<?php echo $id; ?>")', <?php echo $timeLeft; ?>); </script> Quote Link to comment https://forums.phpfreaks.com/topic/170603-solved-php-var-into-js-headache/#findComment-900020 Share on other sites More sharing options...
abazoskib Posted August 17, 2009 Author Share Posted August 17, 2009 It worked! Thank Dj Kat, I think I kept messing up the double and single quotes. I was up till 3:30 last night trying to figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/170603-solved-php-var-into-js-headache/#findComment-900092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.