Jump to content
Cameron

How To Add One Month To An Entered Date With Js?

Recommended Posts

Hi Cameron,

 

How are you?

 

I think, you can use the following script:

<SCRIPT LANGUAGE="JavaScript">
function setDate()
{
     var firstDateFieldName = "first";
     var secondDateFieldName = "second";

     firstDateFieldName = "InsertRecord" + firstDateFieldName;
     secondDateFieldName = "InsertRecord" + secondDateFieldName;

     var f_Date = document.getElementById(firstDateFieldName ).value;
     var first_Date = new Date(Date.parse(f_Date));
     var result_Date = new Date (first_Date.setMonth(first_Date.getMonth()+1));

     var d_month = result_Date.getMonth() + 1;
     if (d_month<10) {d_month = "0" + d_month;}
     var d_day = result_Date.getDate();
     if (d_day<10) {d_day = "0" + d_day;}
     var d_year = result_Date.getFullYear();
     var str_date = d_month + "/" + d_day + "/" + d_year;     
 
     document.getElementById(secondDateFieldName ).value = str_date;
}
document.getElementById("caspioform").onsubmit=setDate;   
</SCRIPT>

Let me know, if something doesn't work.

Share this post


Link to post
Share on other sites

use this in the footer or HTML Block below all elements:

<script>
 document.getElementById('InsertRecorddate').onblur= function (){

var d = new Date( document.getElementById('InsertRecorddate').value );
d.setMonth( d.getMonth( ) + 1 );
 document.getElementById('InsertRecorddate2').value = ( d.getMonth( ) + 1 ) + '/' + d.getDate( ) + '/' + d.getFullYear( );
}
</script>

Replace InsertRecorddate with the ID of the Date field and InsertRecorddate2 by the ID of the field where you want to save the new date.

Share this post


Link to post
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...