Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IIF Syntax Anyone? 1

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
US
Hi,

Am I saying the following correctly? My goal is to set a <cfform> element to a certain value based on the value of another setting:

I'm saying if my current page was called by 'homepage.cfm', set a value, else set another value:

<cfif #session.caller_page# eq 'homepage.cfm'>
<cfset session.processid = 1>
<cfelse>
<cfset session.processid = 2>
</cfif>



....later in the same page I say:


<TABLE width=35% cellpadding=0 cellspacing=0 border=0>
<TR>
<TD><cfinput type=&quot;text&quot; name=&quot;startmonth_sweep&quot; value=&quot;IIF(#session.processid# is 1,#form.startmonth#,#session.startmonth_sweep#)&quot; maxlength=2 size=3></TD>
<TD><cfinput type=&quot;text&quot; name=&quot;startday_sweep&quot; value=&quot;IIF(#session.processid# is 1,#form.startday#,#session.startday_sweep#)&quot; maxlength=2 size=3>/</TD>
<TD><cfinput type=&quot;text&quot; name=&quot;startyear_sweep&quot; value=&quot;IIF(#session.processid# is 1,#form.startyear#,#session.startyear_sweep#)&quot; maxlength=4 size=5></TD>



In all of my books, they use something called DE() within IIF?

Any help's appreciated.

scripter73

Change Your Thinking, Change Your Life.
 
In this case, there's not a need for DE():

[COLOR=008080]<TABLE width=35% cellpadding=0 cellspacing=0 border=0>[/color]
[COLOR=008080]<TR>[/color]
[COLOR=008080]<TD>[/color]<cfinput type=&quot;text&quot; name=&quot;startmonth_sweep&quot; value=&quot;#IIF(session.processid is 1, form.startmonth, session.startmonth_sweep)#&quot; maxlength=2 size=3>[COLOR=008080]</TD>[/color]
[COLOR=008080]<TD>[/color]<cfinput type=&quot;text&quot; name=&quot;startday_sweep&quot; value=&quot;#IIF(session.processid is 1, form.startday, session.startday_sweep)#&quot; maxlength=2 size=3>/[COLOR=008080]</TD>[/color]
[COLOR=008080]<TD>[/color]<cfinput type=&quot;text&quot; name=&quot;startyear_sweep&quot; value=&quot;#IIF(session.processid is 1, form.startyear, session.startyear_sweep)#&quot; maxlength=4 size=5>[COLOR=008080]</TD>[/color]
- tleish
 
I think the IIF function goes like this

IFF( Condition to be evaluated, True do this , False do this)

 
You'll actually need quotes around your variables in the IIF statement; otherwise it won't work in this instance:
Code:
#IIF(session.processid is 1, 'form.startmonth', 'session.startmonth_sweep')#
If you omit the quotes around the variables, the IIF statement tries to evaluate those variables. You can think of this behavior as if you were using Evaluate() around a variable without quotes: it would look inside that variable and treat the value as another variable, which is what you don't want.

Here's an easy IIF lesson:
Code:
#IIF(myvar,dothis,dothat)# - Evaluates the variables dothis and dothat, which means it looks at the value of those variables and treats them as a variable.
Code:
#IIF(myvar,'dothis','dothat')# - Returns the values of the variables dothis and dothat.
Code:
#IIF(myvar,DE('dothis'),DE('dothat'))# - Returns the actual strings &quot;dothis&quot; and &quot;dothat&quot;.
-Tek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top