• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Advance date 90 days when date change in Form

Participant ,
Nov 20, 2009 Nov 20, 2009

Copy link to clipboard

Copied

Good evening all,

I have this:

<cfinput type="datefield" name="startdate" value="#dateformat(Now(), 'mm/dd/yyyy')#">

<cfinput type="datefield" name="nextdate" value="#dateformat(Now() +90, 'mm/dd/yyyy')#" readonly="yes">

I want to advance "nextdate" by 90 days  when "startdate" is changed.

TOPICS
Advanced techniques

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 22, 2009 Nov 22, 2009

Use cfinput's bind attribute, for example


<script type="text/javascript">

/* add 90 days to a given date */
addDays = function(dateStr) {
var newdate = (new Date(dateStr)).add('d',90);
var days = newdate.getDate();
var months = newdate.getMonth()+1;
var year = newdate.getFullYear();

/* the datefield widget requires 2 digits to display*/
if(days < 10) days = '0'+days;
if(months < 10) months = '0'+months;
return months + "/" + days + "/" + year;
}
</script>

<cfform name="dateForm" id="dateForm">
<cfinput type="d

...

Votes

Translate

Translate
Community Expert ,
Nov 22, 2009 Nov 22, 2009

Copy link to clipboard

Copied

Use cfinput's bind attribute, for example


<script type="text/javascript">

/* add 90 days to a given date */
addDays = function(dateStr) {
var newdate = (new Date(dateStr)).add('d',90);
var days = newdate.getDate();
var months = newdate.getMonth()+1;
var year = newdate.getFullYear();

/* the datefield widget requires 2 digits to display*/
if(days < 10) days = '0'+days;
if(months < 10) months = '0'+months;
return months + "/" + days + "/" + year;
}
</script>

<cfform name="dateForm" id="dateForm">
<cfinput type="datefield" name="startdate" value="#dateformat(Now(), 'mm/dd/yyyy')#">
<cfinput type="datefield" name="nextdate" bind="javascript:addDays({dateForm:startdate})" readonly="yes"> 
</cfform>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 23, 2009 Nov 23, 2009

Copy link to clipboard

Copied

BKBK,

Thanks. This is what I was looking for. I made a slight change. I changed the second <cfinput type="text">, I left it readonly so that users cannot change the 90 day date.

<cfform name="dateForm" id="dateForm">
<cfinput type="datefield" name="startdate" value="#dateformat(Now(), 'mm/dd/yyyy')#">
<cfinput type="text" name="nextdate" bind="javascript:addDays({dateForm:startdate})" readonly="yes"> 
</cfform>

Thanks again,

djkhalif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 23, 2009 Nov 23, 2009

Copy link to clipboard

Copied

BKBK,

I couldn't get it to work with flash format.

THanks,

djkhalif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 23, 2009 Nov 23, 2009

Copy link to clipboard

Copied

You're right. Flash doesn't wanna play. I'll have a look.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 28, 2009 Nov 28, 2009

Copy link to clipboard

Copied

I have been returning to the subject. I am still looking for a neat way to do dateAdd in Actionscript, as Coldfusion doesn't allow new Date(). (Coldfusion's flash forms don't allow you to create objects using the new keyword).

In the meantime, why don't you post the "flash" version of your original question in the Rich Forms forum ? It's sure to attract new suggestions.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 28, 2009 Nov 28, 2009

Copy link to clipboard

Copied

Yes, from what I recall there is not much in the way of date functions in Flex 1.5. But one nice thing is you can get away with some of the keywords like "new" using functions.  So you could try and roll your own.  I do not know if the date math works in all scenarios, but here is a quick example.  Note, I cheated and used the internal mx.formatters.DateFormatter() class.

<cfform name="dateForm" id="dateForm" format="flash">
    <cfformitem type="script">
        function addDays(baseDate:Date, numOfDays:Number)
        {
            var newDate = new Date();
            // calculate the days to add in milliseconds 
            var daysToAdd = numOfDays * (24*60*60*1000);
            // add the days to the starting date
            newDate.setTime(baseDate.getTime() +  daysToAdd);
            // format the new date as a string
            var formatter = new mx.formatters.DateFormatter();
            formatter.formatString = "MM/DD/YYYY";
            return formatter.format(newDate);
        }
    </cfformitem>
    <cfinput type="datefield" name="startdate" value="#dateformat(Now(), 'mm/dd/yyyy')#" />
    <cfinput type="text" name="nextdate" bind="{addDays(startdate.selectedDate, 90)}" readonly="yes" />
</cfform>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 28, 2009 Nov 28, 2009

Copy link to clipboard

Copied

@ -==cfSearching==-

Thanks for the new breakthough.

@Djkhalif

Now you're spoilt for choice.

<cfform name="dateForm" id="dateForm" format="flash">
<cfformitem type="script">
function addDays2(numberOfDays,dateObject) {

    // convert date to milliseconds
    var dateValue = dateObject.valueOf();   
    var newDate = new Date(dateValue+numberOfDays*24*60*60*1000);

    // remember getMonth returns 0 to 11 in Actionscript
    return (newDate.getMonth()+1) + "/" + newDate.getDate() + "/" + newDate.getFullYear();
}
</cfformitem>
<cfinput type="datefield" name="startdate" value="#dateformat(Now(), 'mm/dd/yyyy')#" />
<cfinput type="text" name="nextdate" bind="{addDays2(90,startdate.selectedDate)}" readonly="yes" />
</cfform>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 28, 2009 Nov 28, 2009

Copy link to clipboard

Copied

Thanks for the new breakthough.

Haha

    var dateValue = dateObject.valueOf();   

    var newDate = new

Date(dateValue+numberOfDays2460601000);

Nice one. I suspected the constructor might accept milliseconds. But did not see it the documentation I found (granted it was old).

-Leigh

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 01, 2009 Dec 01, 2009

Copy link to clipboard

Copied

LATEST

BKBK and cfSearching,

I apologize for getting back to so late. cfSearching example works.

Thanks,

djkhalif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation