Copy link to clipboard
Copied
Hi,
I want pass a variable for number part in Dateadd() funtion instead of hardcoding it.
Eg:
<cfset var a = 180>
now i want to pass this value of a into "number" part of dateadd function.
DateAdd("d", number, now())
How can be this done..?
Copy link to clipboard
Copied
<cfset var a = 180>
<cfset newDate = DateAdd("d", a, now())>
Copy link to clipboard
Copied
i tried that.but getting error
Copy link to clipboard
Copied
gokul1242 wrote:
i tried that....
No, you didn't. What you tried is equivalent to:
<cfset txt_expiration = "">
<cfset yearAhead = DateAdd("d", txt_expiration, now())>
You will find that the following does work:
<cfset txt_expiration = 180>
<cfset yearAhead = DateAdd("d", txt_expiration, now())>
Copy link to clipboard
Copied
Yes
<cfset txt_expiration = 180>
<cfset yearAhead = DateAdd("d", txt_expiration, now())>
This works. But in my case i am calling txt_expiration value from a sql query through js script as follows
<SCRIPT>
<cfwddx action="cfml2js" input="#qry_category#" topLevelVariable="qj">
function fnselectcat()
{
if(qj.getField(i,"cat_id") == document.frm.sel_category.value)
{
document.frm.txt_expiration.value = qj.getField(i,"CAT_EXPIRATION");
}
}
</SCRIPT>
how to fetch the "txt_expiration" value from script and pass it into the date funtion ??
Copy link to clipboard
Copied
Javascript runs on the browser, ColdFusion on the server. Hence, Javascript variables are not available to ColdFusion.
You are apparently aware of one way of passing the variable to ColdFusion, namely, by submitting a form. The variable is then available on the form's action page as form.txt_expiration.
However, I was wondering why don't just do the obvious. Get the value of txt_expiration directly from the query!
Copy link to clipboard
Copied
the scenario is i have a drop down.based on selecting the drop down value it calls the above onchange js function to display the corresponding
txt_expiration value .but txt_expiration values are in days(eg: 180,365) in db..i need to add it to current date ie now() and convert it and display in dd-mm-yyyy format
Copy link to clipboard
Copied
Run the following test. I hope everything will then become clear. Both CFM pages are within the same directory.
testFormpage.cfm
<SCRIPT>
function fnselectcat()
{ document.frm.txt_expiration.value = 'KARAMBA!';
document.frm.submit();
}
</SCRIPT>
<body onload="fnselectcat()" >
<form name="frm" method="post" action="testActionpage.cfm">
<input name="txt_expiration" type="text">
</form>
</body>
testActionpage.cfm
<cfif isdefined("form.txt_expiration")>
The form has been submitted and the value of form.txt_expiration is: <cfoutput>#form.txt_expiration#</cfoutput>
</cfif>