php - Changing the content between a DIV every day -
i needed js change content of these 2 div's every day on yearly basis. example: on jan 1 date div "jan 1" , moto div moto jan 1, on january 2 date , moto changes not randomly have text each of 365 days. example , can fill out rest. thought js can php on serverside if easier.
<div id="date"><h3>jan 1</h3></div> <div id="moto" align="center">example text.</div>
just humor request i've provided solution...like other answers say, though: best done server-side.
<script> var date = new date(); //get current date var month = date.getmonth(); var day = date.getdate(); var months = ['jan', 'feb', ... , 'dec']; //array of month formats //define mottos multi-dimensional array month , day var mottos = [ [ 'jan 1 motto', 'jan 2 motto', ..., 'jan 31 motto' ], ..., [ 'dec 1 motto', ..., 'dec 31 motto' ] ]; //set date div document.getelementbyid('date').innerhtml = months[month] + " " + day; //set motto div; day - 1 accounts zero-indexed arrays document.getelementbyid('moto').innerhtml = mottos[month][day - 1]; </script>
with php:
<?php //similar above js method $mottos = array( array( 'jan 1 motto', ... ), ... ); $date = new datetime(); $month = (int) $date->format('n'); $day = (int) $date->format('j'); ?> <div id="date"><h3><?php echo strtoupper($date->format('m j')); ?></h3></div> <div id="moto" align="center"><?php echo $motto[$month - 1][$day - 1];</div>
Comments
Post a Comment