pouncer Posted January 26, 2007 Share Posted January 26, 2007 [code] function GetGreeting() { return '<script> var objDate = new Date(); if (objDate.getHours() < 12) document.write("Good morning"); elseif (objDate.getHours() < 16) document.write("Good afternoon"); else document.write("Good evening"); </script>'; }[/code]It's a function inside my php class, but when i do $log->GetGreeting() it just doesn't work. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 View the source to see if it outputs anythingTurn error reporting onMake sure $log is defined. Quote Link to comment Share on other sites More sharing options...
pouncer Posted January 26, 2007 Author Share Posted January 26, 2007 If I use this[code]function GetGreeting() { ?> <script> document.write("dfsdfsd"); </script> <?php}[/code]then $log-GetGreeting() puts dfsdfsd on the page - fine. But this doesnt work:[code] function GetGreeting() { ?> <script> var objDate = new Date(); if (objDate.getHours() < 12) document.write("Good morning"); elseif (objDate.getHours() < 16) document.write("Good afternoon"); else document.write("Good evening"); </script> <?php }[/code] Quote Link to comment Share on other sites More sharing options...
pouncer Posted January 26, 2007 Author Share Posted January 26, 2007 and also:document.write(objDate.getHours());puts 23 on my pageso the javascript stuff is working, but it just doesnt put the good morning of evening stuff on??? :s Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 Then I think the problem is with your javascript code. View the source, if everything is printed to the html page, then it worked. If your HTML page contains this:<script> var objDate = new Date(); if (objDate.getHours() < 12) document.write("Good morning"); elseif (objDate.getHours() < 16) document.write("Good afternoon"); else document.write("Good evening"); </script>Then the problem is NOT the PHP, but the JS. Does JS have an elseif construct? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 26, 2007 Share Posted January 26, 2007 Why are you doing this in Javascript, when it can done in PHP just as easily:[code]<?phpif (date('G') < 12) echo 'Good Morning';elseif (date('G') < 16) echo 'Good Afternoon';else echo 'Good Evening';?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
pouncer Posted January 26, 2007 Author Share Posted January 26, 2007 but isn't that gonna be the time off the server?thats why i was using javascript so its the clients time Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 26, 2007 Share Posted January 26, 2007 Ok.I tried your function on my machine and got a Javascript error until I changed the "esleif" to "else if", then it worked.Ken Quote Link to comment Share on other sites More sharing options...
pouncer Posted January 26, 2007 Author Share Posted January 26, 2007 [quote author=kenrbnsn link=topic=124219.msg514435#msg514435 date=1169854109]Ok.I tried your function on my machine and got a Javascript error until I changed the "esleif" to "else if", then it worked.Ken[/quote]thanks. worked Quote Link to comment 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.