Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to increase and decrease the date by one on click using js?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.02k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: