Jump to content

Need To Increment Value Of Date Fields By One Business Day


Recommended Posts

Hi,

 

I'm new to Caspio. I have a 9 date text fields with calendar picker. When user picks date for 1st field I need the subsequent 8 fields to populate with the 1st field's date + 1 business day. The result would be as follows:

 

field 1 - 01/16/2015 SELECTED

field 2 - 01/19/2015 AUTOPOPULATED

field 3 - 01/20/2015 AUTOPOPULATED

field 4 - 01/21/2015 AUTOPOPULATED

field 5 - 01/22/2015 AUTOPOPULATED

field 6 - 01/23/2015 AUTOPOPULATED

field 7 - 01/26/2015 AUTOPOPULATED

field 8 - 01/27/2015 AUTOPOPULATED

field 9 - 01/28/2015 AUTOPOPULATED

 

THEN SUBMIT*

 

Any help, javascript and/or implementation would be greatly appreciated.

 

Thanks.

Link to comment
Share on other sites

Hello james1234,

 

I have added a Rule to disable field2 - field9 (you can create a new section, move the fields to this section, then add a Rule with the "Value = 1 equal Value = 1" Condition and the "disable the section" Action).

 

I hope the following code helps:

<SCRIPT LANGUAGE="JavaScript">

function nextDate(baseDate)
{
     var base_day = baseDate.getDate();
     base_day = base_day + 1;
     var next_Date = new Date (baseDate.setDate(base_day));
     var week_day = next_Date.getDay();
     if (week_day==0)
     {
          base_day = base_day + 1;
          var next_Date2 = new Date (next_Date.setDate(base_day));
     }
     if (week_day==6)
     {
          base_day = base_day + 2;
          var next_Date2 = new Date (next_Date.setDate(base_day));
     }
return next_Date;
}

function setFormat(next_Date)
{
     var d_month = next_Date.getMonth() + 1;
     if (d_month<10) {d_month = "0" + d_month;}
     var d_day = next_Date.getDate();
     if (d_day<10) {d_day = "0" + d_day;}
     var d_year = next_Date.getFullYear();
     var str_date = d_month + "/" +  d_day + "/" + d_year;
return str_date;
}


function setDates()
{
     var f_Date = document.getElementById("InsertRecordfield1").value;
     var first_Date = new Date(Date.parse(f_Date));
     var second_date = new Date (nextDate(first_Date));
     document.getElementById("InsertRecordfield2").value=setFormat(second_date);
     var third_date = new Date (nextDate(second_date));
     document.getElementById("InsertRecordfield3").value=setFormat(third_date);
     var forth_date = new Date (nextDate(third_date));
     document.getElementById("InsertRecordfield4").value=setFormat(forth_date);
     var fifth_date = new Date (nextDate(forth_date));
     document.getElementById("InsertRecordfield5").value=setFormat(fifth_date);
     var sixth_date = new Date (nextDate(fifth_date));
     document.getElementById("InsertRecordfield6").value=setFormat(sixth_date);
     var seventh_date = new Date (nextDate(sixth_date));
     document.getElementById("InsertRecordfield7").value=setFormat(seventh_date);
     var eights_date = new Date (nextDate(seventh_date));
     document.getElementById("InsertRecordfield8").value=setFormat(eights_date);
     var ninth_date = new Date (nextDate(eights_date));
     document.getElementById("InsertRecordfield9").value=setFormat(ninth_date);
} 

document.getElementById("InsertRecordfield1").onchange=setDates;  
</SCRIPT>

Please insert names of your fields instead of field1-field9.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...