Update end date after choosing start date

Hopefully this is something pretty simple. I need to auto change the departure date on the form right below the slideshow here: http://www.hallmarkinns.com/ when someone chooses a different arrival date than the default seen when entering the page. They'll still need to be able to change the departure date if they want.

I assume jQuery is the best option, but I'm very weak in it to figure out how to do it myself.
LVL 14
DzynitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HainKurtSr. System AnalystCommented:
maybe something like this:

$("#input_6_1").change(function(){
   $( "#input_6_2" ).datepicker( "setDate", $(this).datepicker("getDate")+7 );
});
0
leakim971PluritechnicianCommented:
jQuery(document).reayd(function() {
  var doThat = function(dateText, inst) {  
        var d = new Date(dateText);
        d.setDate(d.getDate() + 10); // add 10 days
        jQuery(".datepicker[name=Departure]").datepicker("setDate", );
  };
  $(".datepicker[name=Arrival]").datepicker( "option", "onSelect", doThat);
});

Open in new window

0
DzynitAuthor Commented:
leakim - nothing happened when I tried yours. It didn't show any errors either.

HainKurt - I change the 7 to 2 to test. The depart date does change, but it jumps to 5 years in the future. That's very strange.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

leakim971PluritechnicianCommented:
line 5 should be :
$(".datepicker[name=Departure]").datepicker("setDate", d);
0
HainKurtSr. System AnalystCommented:
try this:

$("#input_6_1").change(function(){
   var t = new Date();
   t.setDate($(this).datepicker("getDate")+7);
   $( "#input_6_2" ).datepicker( "setDate",  t);
});
0
DzynitAuthor Commented:
I tried that but the screen went white from the slideshow on. The error was $ is not a function, so I changed the $'s to jQuery. The screen displayed correctly then, but got a new error:

Error: TypeError: jQuery(...).datepicker is not a function
0
DzynitAuthor Commented:
My last reply was for leakim.

Hain, That seems a little better. But whether I leave 7 or change that to 2, it set's the depart date 2 days earlier than the start date.
0
HainKurtSr. System AnalystCommented:
i guess you need a bit of checking... you dont want to set departure all the time... maybe once? or maybe when it is lower?

$("#input_6_1").change(function(){
  var d = new Date();

  if ($( "#input_6_2" ).datepicker("getdate") < $(this).datepicker("getDate")) {
    d.setDate($(this).datepicker("getDate")+7);
    $( "#input_6_2" ).datepicker( "setDate", d);
  };
});
0
DzynitAuthor Commented:
I'm echoing this code through php, so I changed the " to single quotes. Could that be causing any problems?
0
HainKurtSr. System AnalystCommented:
or more simply:

$("#input_6_1").change(function(){
  if ($( "#input_6_2" ).datepicker("getdate") < $(this).datepicker("getDate")) {
    $( "#input_6_2" ).datepicker( "setDate", $(this).datepicker("getDate")+7);
  };
});
0
DzynitAuthor Commented:
That last code made it jump 5 years again. The previous still keeps setting the depart -2 days.
0
HainKurtSr. System AnalystCommented:
here it is :)

$("#input_6_1").datepicker();
$("#input_6_2").datepicker();

$("#input_6_1").change(function () {
    //alert($(this).datepicker("getDate"));
    //alert($("#input_6_1").datepicker("getDate"));
    //alert($("#input_6_2").datepicker("getDate"));

    if ($("#input_6_2").datepicker("getDate") < $(this).datepicker("getDate")) {
        var d = new Date();
        d.setDate($(this).datepicker("getDate").getDate() + 7);
        $("#input_6_2").datepicker("setDate", d);
    };
});

Open in new window


test it here
0
DzynitAuthor Commented:
That gives me "datepicker is not a function" error.
I have to keep changing the $ to jQuery, but then that datepicker error shows.
0
HainKurtSr. System AnalystCommented:
why JavaScript date is too difficult to work :) here is modified version

$("#input_6_1").change(function () {
    //alert($(this).datepicker("getDate"));
    //alert($("#input_6_1").datepicker("getDate"));
    //alert($("#input_6_2").datepicker("getDate"));

    if ($("#input_6_2").datepicker("getDate") < $(this).datepicker("getDate")) {
        var d = new Date();
       
        d.setTime($(this).datepicker("getDate").getTime() + 7*24*60*60*1000);
        $("#input_6_2").datepicker("setDate", d);
    };
});

Open in new window


this one is adding 7 days... test here
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HainKurtSr. System AnalystCommented:
try adding this to your html, as is:

jQuery(document).ready(function($){

$("#input_6_1").change(function () {
    if ($("#input_6_2").datepicker("getDate") < $(this).datepicker("getDate")) {
        var d = new Date();
       
        d.setTime($(this).datepicker("getDate").getTime() + 7*24*60*60*1000);
        $("#input_6_2").datepicker("setDate", d);
    };
});

});

Open in new window

0
DzynitAuthor Commented:
That previous worked great! I took the less than (<) check out because they always want it to auto to x days when arrival is changed. Then the customer can still re-change the depart date for a longer stay. Main reason is that there's a minimum stay at each resort location and the company didn't feel it was professional looking that the depart date could show earlier than the arrival. Now I just need to set the amount of days in my php according to which resort location a person is on. And that I know how to do ;)

Here's the final code I used:

jQuery('#input_6_1').change(function () {
        var d = new Date();
        d.setTime(jQuery(this).datepicker('getDate').getTime() + 2*24*60*60*1000);
        jQuery('#input_6_2').datepicker('setDate', d);    
});

Open in new window

0
DzynitAuthor Commented:
Thank you very much! Sorry it went from being simple to such a testy task.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.