Semsem Posted March 22, 2013 Share Posted March 22, 2013 Okay, so my code is (currently) as follows: <? if($_GET['page'] == "startTime"){ if(isset($_POST['newTime'])){ $unix = mktime(0, 0, 0, 1, 1, $_POST['year']); echo ('<script> function closeFB() { $("#startTimeDiv").html("<div id="message"></div>"); $("#message").html("<p>X</p>") .append("<p>X<br><? echo $unix; ?></p>"); $.fancybox.close(); } </script>'); echo '<script type="text/javascript">' , 'closeFB();' , '</script>'; } ?> Then there's a whole big table which ends with: <td colspan="2" align="center"><br /><input class="czas" type="submit" name="newTime" value="Set Start Time" /></td></tr> </form> </table> </div> <? die(); } ?> Okay, so what I want is the user to be able to put in a custom time (in the above code, only the year is currently customizable, that will be expanded when I figure out how to get the year to work). The user inputs the year, which in the form corresponds with the PHP $_POST['year']. So, what I want is for the use to input the year, and when on submit, $_POST['year'] to then contain a number, to then include the mktime function, to then echo the javascript function which also has a php echo of the mktime output, and then to call the javascript function. Every time I include the JS function inside the webpage, instead of what I'm trying to do here and echo it (load it) at the proper time, it pre-runs through mktime and since mktime does not contain a year value until submit, it doesn't work properly. But, when I do it like I've done it and echo JS after the submit button is clicked, the JS function apparently is not working. Any ideas? Struggling with server-side vs client-side to know what I'm doing right/wrong... Quote Link to comment https://forums.phpfreaks.com/topic/276021-php-variable-inside-javascript-delay-load/ Share on other sites More sharing options...
PaulRyan Posted March 22, 2013 Share Posted March 22, 2013 (edited) This line: .append("<p>X<br><? echo $unix; ?></p>"); Should be: .append("<p>X<br>'. $unix .'</p>"); Edited March 22, 2013 by PaulRyan Quote Link to comment https://forums.phpfreaks.com/topic/276021-php-variable-inside-javascript-delay-load/#findComment-1420344 Share on other sites More sharing options...
Semsem Posted March 22, 2013 Author Share Posted March 22, 2013 That doesn't work either. I'm approaching day 4 working on solving this, getting a little frustrated. When I tried this, it didn't work at all: if($_GET['page'] == "startTime"){ if(isset($_POST['newTime'])){ echo '<script>window.location = "anyPage.php"</script>';}?> Don't know why. Even if I move the isset to the top of the page, before the if($_GET, it still doesn't work. The last time ANYTHING worked properly, it was: <? if($_GET['page'] == "startTime"){?> <script> function closeFB() { <? $unix = mktime(0, 0, 0, 1, 1, $_POST['year']); ?> $("#startTimeDiv").html("<div id='message'></div>"); $("#message").html("<p>X</p>") .append("<p>X<br><? echo $unix; ?></p>"); $.fancybox.close(); } </script> With the submit button as follows: <tr> <td colspan="2" align="center"><br /><input class="czas" type="submit" onClick="closeFB();" name="newTime" value="Set Start Time" /></td></tr> </form> </table> </div> <? die(); } ?> And when that ran, it returns a unix timstamp of 946702800, where if I change it to mktime(0, 0, 0, 1, 1, 2015);, it returns 1420092000, which is proper. But, with the former, when I view the source code on the page (before I hit any buttons), and click the link in the source code (via FF) to the anyPage.php?page=startTime, I see: <script> function closeFB() { $("#startTimeDiv").html("<div id='message'></div>"); $("#message").html("<p>Contact Form Submitted!</p>") .append("<p>We will be in touch soon.<br>946702800</p>"); $.fancybox.close(); } </script> The JS ran before the input field had a chance to be inputted and before the button could have been pressed. I know I could make the input field into a JS variable, but that puts me back to square one with how to then pass the JS variable to the PHP mktime function, since it would have to be done before the JS ran. And as stated above, your input, which probably will help eventually, did not solve my problem...but it may be a start to solving my problem. Quote Link to comment https://forums.phpfreaks.com/topic/276021-php-variable-inside-javascript-delay-load/#findComment-1420357 Share on other sites More sharing options...
PaulRyan Posted March 22, 2013 Share Posted March 22, 2013 Put this at the very top of your page: <?PHP error_reporting(E_ALL); ini_set('display_errors', 1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/276021-php-variable-inside-javascript-delay-load/#findComment-1420360 Share on other sites More sharing options...
Semsem Posted March 22, 2013 Author Share Posted March 22, 2013 Notice: Use of undefined constant F - assumed 'F' in /home/..../public_html/...../X.php on line 18Notice: Use of undefined constant d - assumed 'd' in /home/..../public_html/...../X.php on line 18Notice: Use of undefined constant Y - assumed 'Y' in /home/..../public_html/...../X.php on line 18Notice: Use of undefined constant g - assumed 'g' in /home/..../public_html/...../X.php on line 18Notice: Use of undefined constant i - assumed 'i' in /home/..../public_html/...../X.php on line 18Notice: Use of undefined constant sa - assumed 'sa' in /home/..../public_html/...../X.php on line 18Notice: Undefined variable: scheduled in /home/..../public_html/...../X.php on line 24Notice: Undefined index: page in /home/..../public_html/...../X.php on line 58Notice: Undefined index: page in /home/..../public_html/...../X.php on line 68Notice: Undefined index: page in /home/..../public_html/...../X.php on line 79 Line 18: $time = date(F." ".d.", ".Y." ".g.":".i.":".sa,time());Line 24: $scheduled .= "<span style='color:#FF0000'>F</span>";} Line 58: <? if($_GET['page'] != "startTime"){ ?> Line 68: <? if($_GET['page'] == "ajax"){?> Line 79: if($_GET['page'] == "startTime"){?> Nothing of this, as far as I can tell, deals with the JS. However, I'm not sure why any of those lines are throwing (secret) errors. Quote Link to comment https://forums.phpfreaks.com/topic/276021-php-variable-inside-javascript-delay-load/#findComment-1420374 Share on other sites More sharing options...
haku Posted March 23, 2013 Share Posted March 23, 2013 What's line 18? Actually, show us lines 15 - 20 (just to be safe). Make sure you tell us which one is 18. Quote Link to comment https://forums.phpfreaks.com/topic/276021-php-variable-inside-javascript-delay-load/#findComment-1420459 Share on other sites More sharing options...
Semsem Posted March 23, 2013 Author Share Posted March 23, 2013 Line 15:Line 16: microtime_float();Line 17:Line 18: $time = date(F." ".d.", ".Y." ".g.":".i.":".sa,time());Line 19:Line 20: $schedule = mysql_query("SELECT * FROM `downTime` WHERE `isActive`='1'"); Lines 15, 17, and 19 are blank lines. Quote Link to comment https://forums.phpfreaks.com/topic/276021-php-variable-inside-javascript-delay-load/#findComment-1420547 Share on other sites More sharing options...
PaulRyan Posted March 23, 2013 Share Posted March 23, 2013 Replace line 18 with this: $time = date('F d, Y g:i:sa',time()); Quote Link to comment https://forums.phpfreaks.com/topic/276021-php-variable-inside-javascript-delay-load/#findComment-1420548 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.