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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFSCRIPT and TAGS

Status
Not open for further replies.

geokor

Programmer
Aug 16, 2000
126
US
I am trying to use a CFLOCATION from inside a CFSCRIPT block but don't seem to be able to get it working. The documentation seems to indicate that it is NOT possible in one place and possible in another. So my question is, can you use cftags like CFLOCATION inside a CFSCRIPT block?

This is what I want to do:
<CFSCRIPT>
switch(form.rdofilter)
{
case 1:
{
cflocation url=&quot;filter.cfm&quot;;
break;
}
case 0:
{
target=0;
break;
}
}
</CFSCRIPT>

Thanks. George K
 
how about <cflocation url=&quot;filter.cfm&quot;>
 
Unless I'm missing something, you can't use <> tags inside a CFSCRIPT block. It bombs out at the first < and says it doesn't know what to do with it. Do you know a way to do it?
GK
 
anyway why aren't you using some kind of script to do that ?? say, javascript, it's far easier ;]]]
if someone has ever found out how to and why we should use cfscript, i'm interested in knowing more !!
 
You can't do a CFLOCATION like that in a CFSCRIPT block since CFSCRIPT only supports functions and not tags... You could, however rewrite this code like:
Code:
<cfswitch expression=&quot;#form.rdofilter#&quot;>

  <cfcase value=1>
    <cflocation url=&quot;filter.cfm&quot;>
  </cfcase>

  <cfcase value=0>
    <cfset target=0>
  </cfcase>

</cfswitch>
Hope this helps...

DM
 
That's how I had the code to start with. But I wanted to see if I could do it in CFSCRIPT - I was trying to use it more and more BUT have come to the same conclusion as iza. There really doesn't seem to be a good reason to use CFScript. Regular CFTags and Javascript are far easier to use and more powerful. Thanks for all the input everyone!
George K
 
Javascript is client side hence although it works hand in glove with ColdFusion, it cannot be compared with Javascript

Regular ColdFusion tags cannot be used within cfscript however functions expressions and operators can.

For instensive serverside number crunching a brief jump into cfscript is more elegant and faster than a tag based approach. You can always check a value set in cfscript as a regular cfusion variable later on and perform a conditional cflocation.

trivial example

clumsy:
<cfset x=3>
<cfset y=4>
<cfset z=x+y>
<cfoutput>#z#</cfoutput>

intuitive:
<cfscript>
x=2;
y=4;
z=x+y;
</cfscript>

<cfoutput>#z#</cfoutput>


 
you're right thrud that jscript is client side whereas cfusion is server side, and THAT is a difference
still, cfscript misses some functionnality to be more used - to my mind ;-)

thanxxx for the precisions :]
 
It is my understanding that functions within CFSCRIPT tags will execute somewhat faster. That being said, I would think it's probably better to use CFSCRIPT whereever convenient (that is, whenever processing can be accomplished with CFSCRIPT commands and functions and without ColdFusion tags).

It's a shame that you can't nest tags inside of these script blocks. I certainly would use ColdFusion Scripting more often if you could. There's been many times where I've written quite a bit of code with CFSCRIPT, only to have to convert it all back to tag format later when changes dictate use of a regular tag or two. (I hate it when that happens...X-)) DarkMan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top