Jump to content

Button To Create Dates In Fields


Recommended Posts

Hi all,

 

I need a little help- I am creating a simplified scheduling app and have a submission form with 5 different dates fields.  I would like the user to have the option to fill the dates into each field manualy or press a button that would prefill the dates.

 

Example: the user would fill in the InputDate1 field and press the button, the other fields would then be filled as follows: InputDate2 = InputDate1 + 1, InputDate3=InputDate2+1 etc

 

lastle I would like to add code that looks to see if Date is a Sunday and if so adds an additional day (so no schedules are on Sunday).

 

--any assistance would be appreciated!

Link to comment
Share on other sites

Hello James,

 

If I understand correctly, you can add HTML-block after your first Date field.

On the Advanced tab of the first Date, select the "Continue next element on the same line" check box.

 

And enter the code like following into the HTML-block:

<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));
     }
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("InsertRecordfirst").value;
     var first_Date = new Date(Date.parse(f_Date));
     var second_date = new Date (nextDate(first_Date));
     document.getElementById("InsertRecordsecond").value=setFormat(second_date);
     var third_date = new Date (nextDate(second_date));
     document.getElementById("InsertRecordthird").value=setFormat(third_date);
     var forth_date = new Date (nextDate(third_date));
     document.getElementById("InsertRecordfourth").value=setFormat(forth_date);
     var fivth_date = new Date (nextDate(forth_date));
     document.getElementById("InsertRecordfifth").value=setFormat(fivth_date);
}   
</SCRIPT>
<button type="button" class="cbSubmitButton" onclick="setDates()">Click me</button>

Please enter yours fieldnames instead of first, second, third, fourth, fifth in InserRecord constructions.

Also you can enter your text instead of "Click me".

 

I hope, it helps.

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...
×
×
  • Create New...