If the user wants to increase or decrease the date by one, on click of a button, he can easily do this by using the following code.
HTML:
Date: <input type="text" class="dateone" id="datepicker">
<input type="button" onclick="prev();" value="Prev" />
<input type="button" onclick="next();" value="Next" />
Script:
$("#datepicker").datepicker();
function next() {
var currentDate = $("#datepicker").val();
var date = new Date(currentDate);
var newDate = new Date(date);
newDate.setDate(newDate.getDate() + 1);
var dd = newDate.getDate();
var mm = newDate.getMonth() + 1;
var y = newDate.getFullYear();
var someFoarmat = y +"/"+mm+"/"+dd;
$(".titleh2 #datepicker").val(someFoarmat);
}
function prev() {
var currentDate = $("#datepicker").val();
var date = new Date(currentDate);
var newDate = new Date(date);
newDate.setDate(newDate.getDate() - 1);
var dd = newDate.getDate();
var mm = newDate.getMonth() + 1;
var y = newDate.getFullYear();
var someFoarmat = y +"/"+mm+"/"+dd;
$(".titleh2 #datepicker").val(someFoarmat);
}
You can also find the attached demo.
Hope this will help you.
0 Comment(s)