Reputation: 338
I have made this script that get's the month and the year from calendar.php and I would like when I click the link previous month to get the previous month but also when month number reach 1 make the year - 1. How can I do something like that?
<html>
<head></head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script>
$(function() {
get_data();
});
function get_data(a, b) {
$.get('calendar.php', {
month: a, year: b
},
function(response) {
$el = $('<div></div>').attr('class', 'data').html(response);
$('#datas').prepend($el);
height = $el.height()+'px';
$el.css({'opacity': 0, 'display': 'block', 'height': '0px'}).animate({height: height }, 500, function() {
$(this).animate({opacity: 1}, 500);
})
});
}
</script>
<style>
#datas {
overflow: hidden;
}
.data {
display: none;
}
</style>
<body>
<a href="#" OnClick="get_data(9, 2012);" > Previous month</a>
<div id="datas">
</div>
</body>
</html>
Upvotes: 0
Views: 242
Reputation: 2251
I think you should use jQuery.ajax
$.ajax({
url: 'calendar.php',
success: function(data) {
// Parse your data and do all neccessery refreshing
}
});
in order get yerstaday you can use
var d = new Date(/* data that you get from calendar.php*/);
d.setDate(d.getDate() - 1);
Upvotes: 1