Solved

Need to add days from dropdown to current date in jquery

Posted on 2015-01-11
2
198 Views
Last Modified: 2015-01-12
I need to display a  current date and add days from dropdown.

<SELECT class="QTY">
<OPTION VALUE="1">1</OPTION>
<OPTION VALUE="2">2</OPTION>
<OPTION VALUE="3">3</OPTION>
</SELECT>

 <INPUT TYPE=SUBMIT id='Button' VALUE="Go">   
     <input id='checkin' />
     <input id='checkout' />
     <input id='duration' />

$('#Button').click(function(){
    var checkin = new Date();
    var duration = $('.QTY option:selected').val();
    var checkout = new Date();
    
    checkout.setDate(checkin.getDate() + duration); 
    
	$('#checkin').val(checkin); 
    $('#checkout').val(checkout)  
    $('#duration').val(duration)
});

Open in new window

0
Comment
Question by:ucohockey
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 40543857
Try this instead:
    var checkout = new Date(checkin);
    checkout.setDate(checkout.getDate() + Number(duration));

Open in new window

this copies the checkin date, then increases the day of the month by duration days, making sure it's converted from a string to a number. If it passes the end of the month, the Date object will take care of that. I made another fiddle: http://jsfiddle.net/robert_schutt/hpazp71v/
0
 

Author Closing Comment

by:ucohockey
ID: 40543861
Thank You much simpler  then what I came up with.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now