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

CFSCRIPT verses JavaScript

Status
Not open for further replies.

khue

Programmer
Mar 6, 2001
112
US
I'm very new to ColdFusion so help me out on CFSCRIPT. Can someone tell me the following:

1. What's the difference between CFSCRIPT verses JavaScript?
2. What's the advantages/disadvantages?
3. How it is as compared to javascript?
4. How does ColdFusion see and process CFSCRIPT as compared to JavaScript? i.e. can I place CFSCRIPT codes inline in place of CF tags/codes and still produce the same result logically (as in mathematical computation, comparison, etc.,) and physically (as in appearance on the screen)?
5. Can CFSCRIPT variables be used interchangeably with CF variables? i.e. <CFSET myVar = &quot;ColdFusion&quot;>
...
<CFSCRIPT>
...
myVersion = myVar /* Assign CF variable */
...
</CFSCRIPT>

...
<!--- Print CFSCRIPT variable --->
<CFOUTPUT>#myVersion#</CFOUTPUT>
 
i don't know in details, but what i can tell you is :
- javascript is more powerful than cfscript (it can do much much much more things that just processing form datas)
- javascript is well documented whereas cfscript is quite poorly documented
- javascript is CLIENT side whereas cfscript is SERVER side

i developped a huge app, using javascript, coldfusion & html - i didn't use at all cfscript
all validations where done using javascript
javascript function were (sometimes) using cf variables (see the faqs on this forum)

i would suggest NOT to use cfscript as javascript does it already, and better .... but maybe i'm wrong ....
 
There are advantages to proccessing things &quot;server side&quot; (Like you can be 100% sure that your users arn't playing games with you)

CFSCRIPT is a faster replacment to multiple CFSET's (and much tidier for many other things) I saw an interesting performance &quot;matrix&quot; the other day... CFSCRIPT can be faster than CFX tags (ok, not always but...)

Try using JavaScript to access a database :)

So, they are different, and both very useful.
 
iza and CFHub, both of you have answered questions 1 - 3 but questions 4 and 5 have not been answered. Please detail some info on questions 4 and 5.

Plus, are there any good programming books specifically on ColdFusion CFSCRIPT?
 
4. Like iza said, CFSCRIPT is server-side whereas JavaScript is client-side. This means, any code in a <CFSCRIPT> tag is going to be processed by the server. Sometimes this is a good thing (CF_HUB , good examples.) There are many things you might want to do that really don't need to be done on the server. This is where JavaScript is nice. JavaScript code is executed on the client's machine. In other words, once the user's browser has rendered your page, anything he/she does (using JavaScript) is processed on his/her machine...no load on your server.

5. Yes, you can use variables between CFSCRIPT and plain ol' CF. For example, if you set a variable in <CFSCRIPT> like this:
Code:
<CFSCRIPT>
   myVar = &quot;Kevin&quot;;
</CFSCRIPT>
You can throw it in a regular <CFOUTPUT> tag and use it. Conversely, you can set a variable using <CFSET> and use it in a <CFSCRIPT>.

Hope this helps. Kevin
slanek@ssd.fsi.com
 
4. Anything that is between <CFSCRIPT></CFSCRIPT> is sent to the ColdFusion application server for processing. The ColdFusion Server ignores client side javascript because that will processed by the browser.

<CFSCRIPT> can be included inline and the same results will occur.

5. Any variables that you set with <CFSET> can be accessed within the CFSCRIPT tag. There is no difference between variables declared with <CFSET> and variables declared within the CFSCRIPT tag

 
Thanks to all of your answers...
 
CFHub don't misunderstand me ! this is NOT a good idea to access db using jscript (even if it CAN be done ...) - as accessing db is done server side, you might as well use cf - javascript is the best way to do for every CLIENT SIDE operation, as it doesn't send requests to the server (whereas cfscript does) : this fasten things up !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top