Jump to content

Recommended Posts

Add this code to the footer of the page. Make sure to replace "DATEFIELDNAME" with the field name you want to save this expiration date on

<script>
function f_date(){
var v_currentDate=new Date();

v_currentDate.setDate(v_currentDate.getDate() +10);
var v_assignDate = (v_currentDate.getMonth() + 1) + "/" + v_currentDate.getDate() + "/" + (v_currentDate.getFullYear());
document.getElementById('InsertRecordDATEFIELDNAME').value = v_assignDate;

}
f_date();
</script>
Link to comment
Share on other sites

  • 4 months later...
  • 2 weeks later...

I would like my expiration date to be one year from the date entered (not necessarily today's date):

 

Date Signed: 7/1/2015

Expiration Date: 7/1/2016

 

How would I adjust the javascript to accomplish that?

 

Thanks!

 

Hi Ababcock,

 

How are you? How's the weather in your city?

 

I think, this script can help:

<SCRIPT LANGUAGE="JavaScript">

function setDate()
{
     var stringDate = document.getElementById("InsertRecordDATE_SUBMIT").value;
     var myDate = new Date(Date.parse(stringDate));
     myDate.setFullYear(myDate.getFullYear()+1);
     var myMonth = myDate.getMonth() + 1;
     if (myMonth<10) {myMonth = "0" + myMonth;}
     var myDay = myDate.getDate();
     if (myDay<10) {myDay = "0" + myDay;}
     var myYear = myDate.getFullYear();
     var result = myMonth + "/" +  myDay + "/" + myYear;
     document.getElementById("InsertRecordEXPIRATION_DATE").value=result;
}   

document.getElementById("caspioform").onsubmit=setDate;
</SCRIPT>

Don't forget to change names of fields, DATE_SUBMIT and EXPIRATION_DATE to names of yours fields.

 

I'll be grateful, if you tell me if the code works.

Have a nice day!

Link to comment
Share on other sites

In a submission form I have a field called Joined. This is a timestamp for the date of submission. I need to add one year to this time which is current day to this and have it reflect in the Expiration field. I have read and tried may things but nothing has worked.

 

Thanks.

 

Hi Shelley,

 

Welcome to our community! How are you? How's the weather in your city?

 

"Timestamp" is set only when a record is added to a table, and the code cannot get the value of this parameter. If you have used alert to see the value of the field, it is "SYSDATE" until the record is created in the table.

 

The "new Date();" method returns the current time, usually it's not worse than Timestamp.

I hope, this code can help:

<SCRIPT LANGUAGE="JavaScript">

function setDate()
{
     var myDate = new Date();
     myDate.setFullYear(myDate.getFullYear()+1);
     var myMonth = myDate.getMonth() + 1;
     if (myMonth<10) {myMonth = "0" + myMonth;}
     var myDay = myDate.getDate();
     if (myDay<10) {myDay = "0" + myDay;}
     var myYear = myDate.getFullYear();
     var result = myMonth + "/" +  myDay + "/" + myYear;
     document.getElementById("InsertRecordsecond").value=result;
}   

document.getElementById("caspioform").onsubmit=setDate;
</SCRIPT>

I'll be grateful, if you tell me if the code works.

Have a nice day!

Link to comment
Share on other sites

  • 1 month later...

Hi Ababcock,

 

How are you? How's the weather in your city?

 

I think, this script can help:

<SCRIPT LANGUAGE="JavaScript">

function setDate()
{
     var stringDate = document.getElementById("InsertRecordDATE_SUBMIT").value;
     var myDate = new Date(Date.parse(stringDate));
     myDate.setFullYear(myDate.getFullYear()+1);
     var myMonth = myDate.getMonth() + 1;
     if (myMonth<10) {myMonth = "0" + myMonth;}
     var myDay = myDate.getDate();
     if (myDay<10) {myDay = "0" + myDay;}
     var myYear = myDate.getFullYear();
     var result = myMonth + "/" +  myDay + "/" + myYear;
     document.getElementById("InsertRecordEXPIRATION_DATE").value=result;
}   

document.getElementById("caspioform").onsubmit=setDate;
</SCRIPT>

Don't forget to change names of fields, DATE_SUBMIT and EXPIRATION_DATE to names of yours fields.

 

I'll be grateful, if you tell me if the code works.

Have a nice day!

 

Can someone adapt this script to be six months from the entered date instead of one year.

 

Thank you.! 

Link to comment
Share on other sites

Can someone adapt this script to be six months from the entered date instead of one year.

 

Thank you.! 

 

I can :)

I have wrote more universal script, you can add days, months, and years. If you want add only month, set "0" for days and years.

And do not forget to enter the name of your field instead of "NAME_OF_YOUR_FIELD"

<SCRIPT LANGUAGE="JavaScript">
function setDate()
{
     var plusDays = 0;
     var plusMonths = 6;
     var plusYears = 0;
     var fieldname = "NAME_OF_YOUR_FIELD";     

     var myDate = new Date();
     myDate.setDate(myDate.getDate()+plusDays);
     myDate.setMonth(myDate.getMonth()+plusMonths);
     myDate.setFullYear(myDate.getFullYear()+plusYears);
     var myMonth = myDate.getMonth() + 1;
     if (myMonth<10) {myMonth = "0" + myMonth;}
     var myDay = myDate.getDate();
     if (myDay<10) {myDay = "0" + myDay;}
     var myYear = myDate.getFullYear();
     var result = myMonth + "/" +  myDay + "/" + myYear;
     fieldname = "InsertRecord"+fieldname;
     document.getElementById(fieldname).value=result;
}   
document.getElementById("caspioform").onsubmit=setDate;
</SCRIPT>

Have a nice day!

Link to comment
Share on other sites

Hi Ababcock,

 

How are you? How's the weather in your city?

 

I think, this script can help:

<SCRIPT LANGUAGE="JavaScript">

function setDate()
{
     var stringDate = document.getElementById("InsertRecordDATE_SUBMIT").value;
     var myDate = new Date(Date.parse(stringDate));
     myDate.setFullYear(myDate.getFullYear()+1);
     var myMonth = myDate.getMonth() + 1;
     if (myMonth<10) {myMonth = "0" + myMonth;}
     var myDay = myDate.getDate();
     if (myDay<10) {myDay = "0" + myDay;}
     var myYear = myDate.getFullYear();
     var result = myMonth + "/" +  myDay + "/" + myYear;
     document.getElementById("InsertRecordEXPIRATION_DATE").value=result;
}   

document.getElementById("caspioform").onsubmit=setDate;
</SCRIPT>

Don't forget to change names of fields, DATE_SUBMIT and EXPIRATION_DATE to names of yours fields.

 

I'll be grateful, if you tell me if the code works.

Have a nice day!

 

Thank you, Xiang, that worked perfectly!

Link to comment
Share on other sites

I can :)

I have wrote more universal script, you can add days, months, and years. If you want add only month, set "0" for days and years.

And do not forget to enter the name of your field instead of "NAME_OF_YOUR_FIELD"

<SCRIPT LANGUAGE="JavaScript">
function setDate()
{
     var plusDays = 0;
     var plusMonths = 6;
     var plusYears = 0;
     var fieldname = "NAME_OF_YOUR_FIELD";     

     var myDate = new Date();
     myDate.setDate(myDate.getDate()+plusDays);
     myDate.setMonth(myDate.getMonth()+plusMonths);
     myDate.setFullYear(myDate.getFullYear()+plusYears);
     var myMonth = myDate.getMonth() + 1;
     if (myMonth<10) {myMonth = "0" + myMonth;}
     var myDay = myDate.getDate();
     if (myDay<10) {myDay = "0" + myDay;}
     var myYear = myDate.getFullYear();
     var result = myMonth + "/" +  myDay + "/" + myYear;
     fieldname = "InsertRecord"+fieldname;
     document.getElementById(fieldname).value=result;
}   
document.getElementById("caspioform").onsubmit=setDate;
</SCRIPT>

Have a nice day!

 

Thank you for this. Its almost there. 

 

This add Six Months to current date. I would like to add Six Months to a date entered on a previous field on submit.

 

Thank you Xiang

Link to comment
Share on other sites

Thank you for this. Its almost there. 

 

This add Six Months to current date. I would like to add Six Months to a date entered on a previous field on submit.

 

Thank you Xiang

I am sorry :rolleyes: Here the script code for the entered value:

<SCRIPT LANGUAGE="JavaScript">

function setDate()
{
     var plusDays = 0;
     var plusMonths = 6;
     var plusYears = 0;
     var dateFieldName = "Name_Of_the_field_with_Entered_date";
     var fieldname = "Name_Of_the_field_with_Result_date";     

     dateFieldName = "InsertRecord" + dateFieldName;
     var entered_value = document.getElementById(dateFieldName).value;
     var myDate = new Date(entered_value);
     myDate.setDate(myDate.getDate()+plusDays);
     myDate.setMonth(myDate.getMonth()+plusMonths);
     myDate.setFullYear(myDate.getFullYear()+plusYears);
     var myMonth = myDate.getMonth() + 1;
     if (myMonth<10) {myMonth = "0" + myMonth;}
     var myDay = myDate.getDate();
     if (myDay<10) {myDay = "0" + myDay;}
     var myYear = myDate.getFullYear();
     var result = myMonth + "/" +  myDay + "/" + myYear;
     fieldname = "InsertRecord"+fieldname;
     document.getElementById(fieldname).value=result;
}   

document.getElementById("caspioform").onsubmit=setDate;
</SCRIPT>

Have a nice day!

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