Eventually I'd like a system where I can schedule events, but I'm using this JavaScript right now but I'd like to be using inline php. Hoping someone could help me write it correctly for in the body of the document. Thanks! <script type="text/javascript">var date=new Date(); var year=date.getFullYear(); var month=date.getMonth(); var day=date.getDate(); // fixed function SetDivContent() { var div=document.getElementById('date_dependent'); if (year==2012 && month==10) { // fixed (the JavaScript months order is 0-11, not 1-12) if (day>=6 && day<8) { // the following content will be displayed 12/03/2010, 12/04/2010, [...], 12/09/2010, 12/10/2010 div.innerHTML='images/ud-calendar.png'; } else if (day==9 || day==13) { // this one will be displayed 12/11/2010 and 12/12/2010 div.innerHTML='images/ud-calendar.png'; } else if (day>13) { // this one - 12/13/2010 and later, until the end of December div.innerHTML='images/ud-calendar.png'; } } else if (year==2013 && month>=0) div.innerHTML='images/ud-calendar.png'; // OPTIONAL - just to ensure that content 3 is displayed even after December. } </script> Code (markup):
echo '<script type="text/javascript">var date=new Date(); var year=date.getFullYear(); var month=date.getMonth(); var day=date.getDate(); // fixed function SetDivContent() { var div=document.getElementById("date_dependent"); if (year==2012 && month==10) { // fixed (the JavaScript months order is 0-11, not 1-12) if (day>=6 && day<8) { // the following content will be displayed 12/03/2010, 12/04/2010, [...], 12/09/2010, 12/10/2010 div.innerHTML="images/ud-calendar.png"; } else if (day==9 || day==13) { // this one will be displayed 12/11/2010 and 12/12/2010 div.innerHTML="images/ud-calendar.png"; } else if (day>13) { // this one - 12/13/2010 and later, until the end of December div.innerHTML="images/ud-calendar.png"; } } else if (year==2013 && month>=0) div.innerHTML="images/ud-calendar.png"; // OPTIONAL - just to ensure that content 3 is displayed even after December. } </script>'; Code (markup):
What's it doing/not doing? During 2012 it will only work during November. If you run it now, it will execute the last condition, div.innerHTML="images/ud-calendar.png" - but only until the end of November, due to if (year==2012 && month==10). (Actually it doesn't matter what the date is - that's the same image for all dates.) And you might want to try div.innerHTML="<image src=\'images/ud-calendar.png\' />";
It's only displaying the default, even when the dates are correct. I'm trying to do it with inline php
If by "the default" you mean ud-calendar.png, that's what the code is telling it to display in all cases. (All your if statements end in displaying ud-calendar.png.) I don't know what ud-calendar.png looks like. I assume it's a calendar of some sort. If you expect it to look different for the different if conditions, that's not going to happen. A png is what it is, and it always looks the same.
Sorry I didn't realize the instance I copied and pasted did that. I did that after the script wouldn't display the correct image. So there were 3. "UD-blackwednesday.png". "UD-Christmas.png" and then the calendar. I think I've got one that will work. I will post it later tonight.
I just tested this and it's still not working... maybe it has something to do with the date call? <?php $date=date("m/d/Y g:ia"); if(strtotime($date) >= strtotime('11/27/2012 08:30pm') && strtotime($date) < strtotime('11/27/2012 08:40pm')) { echo "<a href=\"#\"><img src=\"images/ud-closed-sandy.png\" border=\"0\" ></a>"; } elseif(strtotime($date) >= strtotime('11/27/2012 08:40pm') && strtotime($date) < strtotime('11/27/2012 08:50pm')) { echo "<a href=\"#\"><img src=\"images/ud-halloween.png\" border=\"0\" ></a>"; } else { echo "<a href=\"#\"><img src=\"images/ud-calendar.png\" /></a>"; } ?> <?php $date=date("m/d/Y g:ia"); if(strtotime($date) >= strtotime('11/14/2012 10:00am') && strtotime($date) < strtotime('11/30/2011 1:00am')) {?> <?php }?> PHP:
That will tell you whether the tests (the 'if' statements) have a chance of working. You can do the same thing before each 'if' statement to see what you should expect the action to be. (You really should be running Firebug and FirePHP, so you can throw variables to the browser to see what your program is doing, step by step if necessary.) Also, if you use single quotes for the echo statements, you won't need to escape the double quotes.