Auto Populate dates based off week end date

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
jamesyesjames
User
Posts: 22

Auto Populate dates based off week end date

Post by jamesyesjames »

Dear all!

I've build a time logging system for logging times and jobs over a week - basically a time sheet program.

I have a Date field at the start, which is the week ending date (ie. the last Saturday) and 7 more date fields for each day of the week which a user has worked.

I would like it so that the user selects the week ending date at the beginning then I would like the system to auto populate the other 7 dates based on that week ending date.

Can this be done? If so Please do help

Thanks,
James


danielc
User
Posts: 1601

Post by danielc »

You can easily modify the field after you selected a date. Use jQuery .change event to trigger the filling of other date (see api.jquery.com/change/) and put these code to Startup script for your page. And Use:
$("#x_yourselectdate").change(function() {
var start = $("x_yourselectdate").val();
var stop = new Date(start);
var stop = stop.setDate( stop.getDate() + 1 ); // add one day
var stopd = new Date(stop);
// then you need to format this date to your desired format and use jQuery .val("yourvalue") to update the target field
});


jamesyesjames
User
Posts: 22

Post by jamesyesjames »

Hi Danielc,

I got your script working as below but get a crazy result! I'm using the date format of dd/mm/yy

$("#x_Week_Ending_date").change(function() {
var start = $("#x_Week_Ending_date").val();
var stop = new Date(start);
var stop = stop.setDate( stop.getDate() - 1 ); // sub one day
var stopd = new Date(stop);
$("#x_Date_fri_12D1").val(stopd);
});

If I select the 16/8/14 I get the result of = Wed Apr 07 1915 00:00:00 GMT+0100 (GMT Standard Time)

Any ideas ??


danielc
User
Posts: 1601

Post by danielc »

JavaScript date object take 4 digit for Year. So, you need to manipulate your variable (start) first.


Post Reply