James Thompson James Thompson - 5 months ago 10
jQuery Question

How to automatically change countdown

i got countdown script for one months so how i can do when countdown till zero then it should be automatically change to new countdown date for next months? without for me to manually change it every months myself.

its javascript

<script type="text/javascript">
jQuery(document).ready( function($){
var newDate = new Date(2016, 4, 21);
newDate.setHours(newDate.getHours() + 18);
$('#countdown-ex1').countdown({until: newDate});
});
</script>


and Html

<div id="countdown-ex1" class="countdown countdown-large coming-soon divcenter bottommargin" style="max-width:700px;"></div>

Answer

So you should put in DB the desired dates. Create a function in module that gets the next date, sends that to controller, and in controller you should have something like this :

    $this->load->model('event_model');      
    $next = $this->event_model->getNext()[0]->next_date;    
    $next_date = explode("/",$next);

    $year = $next_date[0];
    $month = $next_date[1];
    $day = $next_date[2];

    $data['date_year'] = $year;     
    $data['date_month'] = $month;       
    $data['date_day'] = $day;   

In your HTML you should put :

    var newDate = new Date(<?php echo $date_year; ?>, <?php echo $date_month; ?>, <?php echo $date_day; ?>);

For managing the dates you can delete manually in admin or whatever, or make some kind of script that checks actual date/time and deletes the records passed of the date.

Thats all, hope it helps