I am trying to do a next/previous button on my calendar to show the next/previous month.
Ideally, the best thing would be not to refresh the page, but in the first place I don't mind having to refresh the page.
I have got a calendar($m,$y) function in php that let me change the value of my calendar directly in the url. For exemple (it's an image) : http://localhost/VELO/index1.php?mois=3&year=2019
So basically, in this exemple, I would like my previous button to change the url to ".../index1.php?mois=2&year=2019"
I tried the following code (and many others) from one of the most answered question about this subject but it didn't worked :
<script>
function getQueryVariable(variable) {
var query = url.substring(1);
var vars = query.split('&');
for (var i=0; i<vars.length; i++) {
var pair = vars[i].split('=');
if (pair[0] == variable) {
return pair[1];
}
}
return false;
}
var url = 'http://localhost/VELO/index1.php?mois=3&year=2019'
var mois = getQueryVariable(url, 'mois');
var year = getQueryVariable(url, 'year');
var params = { 'mois':2, 'year':2019};
var new_url = 'http://localhost/VELO/index1.php?' + jQuery.param(params);
// With this in my <body> :
// <button type="button" class="precedent"><a href="new_url">Prev</a></button>
</script>
But I am getting the following error :
The requested URL /VELO/new_url was not found on this server
In summary, what I am asking is :
- Is the code I am using not appliable in this case ?
- Is there an other way to change my url with a button ? (can I use $_GET['month'] ?)
- Is it possible to do this without refreshing the page ?