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.
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
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>
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
Copy link to clipboard
Copied
BKBK,
I couldn't get it to work with flash format.
THanks,
djkhalif
Copy link to clipboard
Copied
You're right. Flash doesn't wanna play. I'll have a look.
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.
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>
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>
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
Copy link to clipboard
Copied
BKBK and cfSearching,
I apologize for getting back to so late. cfSearching example works.
Thanks,
djkhalif