Jump to content
  • 0

How Do I Select A Date In One Field And Have All Subsequent Date Fields Fill In Automagically


Dilts
 Share

Question

Hello Everyone! 

 

I have found some great answers on this forum for most of my issues but cannot find anything regarding this specific question I have. sincerely appreciate any offers of help. 

 

Currently I have a DataPage which outputs 5 text fields with a calender popup next to each (see attached img).  

post-17837-0-12696600-1424386775_thumb.p

I would like to select a date via the popup in the first field and have the subsequent fields all populate with the next day. So if you select 2/19/2015 then the output in the next data field is 2/19/2015 and so on.

 

I believe that I can do this via some custom JS if I need to, but I wasn't sure if Caspio Bridge can help me do so automatically through a selection in the "Web Form Wizard- Configure Fields". 

 

I appreciate you checking out my post and any help you can offer! 

 

Cheers,

Dilts

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Good morning,

 

I had a similar questions answered recently by Jan here.

 

All you will need to do is scrap the part about changing the days around and edit the field names and it should work pretty well.

 

If you have any questions I can try and take a stab at them but I am pretty new to the Javascript business myself.

Link to comment
Share on other sites

  • 0

Hello Dilts,

 

You can find the code for 10 fields that are auto-filled with next business day. You can easily change it to 5 fields.

 

If you need every next day (I mean, Saturdays and Sundays too) you can use the following code:

<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();
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);
} 

document.getElementById("InsertRecordfield1").onchange=setDates;  
</SCRIPT>
Please, enter names of your fields instead of field1, field2, field3, field4, field5.
 
I hope, it helps.
Link to comment
Share on other sites

  • 0

Thank you very much DataCobalt! I essentially modified what was suggested in the link you sent me to fit my needs. Thank you so much for your quick and accurate response! The ONLY reason I did not mark your question as the answer that solved my question was because the incomparable Jan attached code to her response which would help future users quicker. Thanks so much for your response! 

 

 

Good morning,

 

I had a similar questions answered recently by Jan here.

 

All you will need to do is scrap the part about changing the days around and edit the field names and it should work pretty well.

 

If you have any questions I can try and take a stab at them but I am pretty new to the Javascript business myself.

Link to comment
Share on other sites

  • 0

Fantastic Jan! I did not get around to posting my solution in time but I think yours is better for any future questions related to this issue anyway! I have only been using Caspio for 3 days and I can see that you are the most prolific poster in this forum. Thank you for all the work you do here and your time spent in answering my question! I'll try to make it more difficult for you in the future...  ;)

 

 

Hello Dilts,

 

You can find the code for 10 fields that are auto-filled with next business day. You can easily change it to 5 fields.

 

If you need every next day (I mean, Saturdays and Sundays too) you can use the following code:

<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();
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);
} 

document.getElementById("InsertRecordfield1").onchange=setDates;  
</SCRIPT>
Please, enter names of your fields instead of field1, field2, field3, field4, field5.
 
I hope, it helps.

 

Link to comment
Share on other sites

  • 0

Thank you very much DataCobalt! I essentially modified what was suggested in the link you sent me to fit my needs. Thank you so much for your quick and accurate response! The ONLY reason I did not mark your question as the answer that solved my question was because the incomparable Jan attached code to her response which would help future users quicker. Thanks so much for your response! 

Hear hear! Jan has been saving my bacon on a near weekly basis.

 

Glad you got it solved though!

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
Answer this question...

×   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...