Skip to main content

Posts

Showing posts with the label cfscript

ColdFusion CFscript - Invoke a component in script

cfscript - invoke component artscomponent.cfc <cfcomponent displayname="ArtsCFC" hint="Art Discover"> <cffunction name="GetArts" access="remote" returntype="query"> <cfargument name="ArtistID" type="numeric" required="yes"> <cfargument name="MaximumPrice" type="numeric" required="yes"> <cfquery name="ArtDetails" datasource="cfcodeexplorer"> Select ArtName, Description, Price From ART Where ArtistID = #arguments.ArtistID# And Price <= #arguments.MaximumPrice# </cfquery> <cfreturn ArtDetails> </cffunction> </cfcomponent> invokecomponentcfscript.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>How...

ColdFusion CFscript - Get query result output in script

cfscript - get query result output cfscriptQuery.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>cfscript tag: How to get query result output in cfscript</title> </head> <body> <h2 style="color:DodgerBlue; font-style:italic">cfscript example: Query Output</h2> <hr width="350" align="left" color="PaleVioletRed" /> <cfquery name="qEmployee" datasource="cfdocexamples"> SELECT Emp_ID, FirstName, LastName FROM Employees </cfquery> <h3 style="color:RosyBrown; font-style:italic;"> <u>Employee List</u> <br /> <cfscript> for(Counter=1; Counter LTE qEmployee.RecordCount; Counter++) { WriteOutput(qEmployee.Emp_ID[Counter]); WriteOutput(" : "); WriteOutput(qEmployee...

ColdFusion CFscript - Perform while loop in script

cfscript - while loop in script cfscriptWhile.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>cfscript tag: How to use while loop in cfscript</title> </head> <body> <h2 style="color:DodgerBlue; font-style:italic">cfscript example: while loop</h2> <hr width="350" align="left" color="PaleVioletRed" /> <br /> <b> <cfscript> counter = 1; while(counter LTE 5){ WriteOutput("Counter Now: #counter# <br />") ; counter = counter+1; } </cfscript> </b> </body> </html> More ColdFusion examples cftry and cfcatch - catch exception and handle error cfdiv cfscript - array in script cfscript - if else conditional statement in script cfscript - structure in script cfscript - switch, case,...

ColdFusion CFscript - Create custom function in script

cfscript - create, call and use function cfscriptFunction.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>cfscript tag: How to create, call and use function in cfscript</title> </head> <body> <h2 style="color:DodgerBlue; font-style:italic">cfscript example: create function</h2> <hr width="350" align="left" color="PaleVioletRed" /> <h3 style="color:CornflowerBlue;"> <cfscript> function hello (userName){ sayHello = "Hello #userName# !"; return sayHello; } WriteOutput("#hello("Jones")#"); </cfscript> </h3> </body> </html> More ColdFusion examples cfscript - call user defined function (UDFs) in script cfscript - do while loop in script cfscript - ...

ColdFusion CFscript - For loop in script

cfscript - for loop in script cfscriptForLoop.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>cfscript tag: How to use for loop in cfscript</title> </head> <body> <h2 style="color:DodgerBlue; font-style:italic">cfscript example: for loop</h2> <hr width="350" align="left" color="PaleVioletRed" /> <h4 style="color:DarkBlue;"> <cfscript> for(i=1; i LTE 10; i++){ WriteOutput("Current Position: #i# <br />") ; } </cfscript> </h4> </body> </html> More coldfusion examples cfscript - call user defined function (UDFs) in script cfscript - do while loop in script cfscript - create, call and use function in script cfwindow cfwindow - modal window ajax function -...

ColdFusion CFscript - Do while loop in script

cfscript - do while loop in script cfscriptDoWhile.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>cfscript tag: How to use do while loop in cfscript</title> </head> <body> <h2 style="color:DodgerBlue; font-style:italic">cfscript example: do while loop</h2> <hr width="350" align="left" color="PaleVioletRed" /> <h4 style="color:SeaGreen;"> <cfscript> counter = 1; do{ WriteOutput("Current Position: #counter# <br />") ; counter = counter+1; } while(counter LTE 6); </cfscript> </h4> </body> </html> More ColdFusion examples cftry and cfcatch - catch exception and handle error cfdiv cfscript - if else conditiona...

ColdFusion CFscript - Call user defined function in script

cfscript - call user defined function (UDFs) in script cfscriptCallFunction.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>cfscript tag: How to call user defined function (UDFs) in cfscript</title> </head> <body> <h2 style="color:DodgerBlue; font-style:italic">cfscript example: function call</h2> <hr width="350" align="left" color="PaleVioletRed" /> <cffunction name="Hello" access="remote"> <cfargument name="userName" type="string"> <cfreturn "Hello #userName# !"> </cffunction> <h3 style="color:SaddleBrown;"> <cfscript> WriteOutput("#Hello("Jenny")#"); </cfscript> </h3> </body> </html> Mo...

ColdFusion CFscript - Switch case statement in script

cfscript - switch, case, default statement in script cfscriptSwitch.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>How to use switch, case, default statement in cfscript tag</title> </head> <body> <h2 style="color:DodgerBlue; font-style:italic">cfscript example: switch statement</h2> <hr width="350" align="left" color="PaleVioletRed" /> <br /> <cfform name="HelloForm" method="post"> Favorite Color: <cfinput type="text" name="FavColor"> <cfinput name="Submit" type="submit" value="Submit"> </cfform> <br /> <cfscript> if (IsDefined("Form.Submit") and (Form.FavColor neq "")) { switch(Form.FavColor){ ca...

ColdFusion CFscript - Create Structure in script

cfscript - structure in script cfscriptStructure.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>cfscript tag: How to create and use structure in cfscript</title> </head> <body> <h2 style="color:DodgerBlue; font-style:italic">cfscript example: Structure</h2> <hr width="350" align="left" color="PaleVioletRed" /> <br /> <cfscript> ColorStruct = StructNew(); ColorStruct.Name = "BlueViolet"; ColorStruct.Value = "##8A2BE2"; </cfscript> <cfif IsDefined("ColorStruct")> <cfdump var="#ColorStruct#"> </cfif> </body> </html> More ColdFusion examples cfscript - if else conditional statement in script cfscript - switch, case, default statement in script cfw...

ColdFusion CFscript - If else statement in script

cfscript - if else conditional statement in script cfscriptIfElse.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>How to use if else conditional statement in cfscript tag</title> </head> <body> <h2 style="color:DodgerBlue; font-style:italic">cfscript example: if else</h2> <hr width="350" align="left" color="PaleVioletRed" /> <br /> <cfform name="HelloForm" method="post"> Name: <cfinput type="text" name="UserName"> <cfinput name="Submit" type="submit" value="Submit"> </cfform> <br /> <cfscript> if (IsDefined("Form.Submit")) { if (Form.UserName neq "") { WriteOutput("Hello "); WriteOutp...

ColdFusion CFscript - Assign variable in script

cfscript - assign variable in script cfscriptAssignVariable.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>cfscript tag: how to assign variable in cfscript tag</title> </head> <body> <h2 style="color:DodgerBlue; font-style:italic">cfscript tag example: assign variable</h2> <hr width="350" align="left" color="PaleVioletRed" /> <br /> <cfscript> firstNumber = 10; secondNumber = 5; sum = firstNumber+secondNumber; WriteOutput("<h3 style='color:Crimson; font-weight:bold'>"); WriteOutput("Sum of two numbers [10+5]: "); WriteOutput(sum); WriteOutput("</h3>"); </cfscript> </body> </html> More ColdFusion examples cftry and cfcatch - catch exception and handle...

ColdFusion CFscript: How to create an array in script

Introduction ColdFusion is a powerful and flexible platform for web development, offering a variety of ways to handle dynamic data, including arrays. Arrays are fundamental data structures in many programming languages, and ColdFusion's CFScript tag provides a JavaScript-like syntax for working with them. In this tutorial example, we explore how to create and manipulate arrays in CFScript, an approach that allows for more concise and readable code compared to traditional CFML. The example presented demonstrates how to initialize an array, append elements to it, and display its contents using ColdFusion's tools. Understanding how arrays work in CFScript will help streamline data management in your web applications, enabling more efficient handling of lists, collections, and sequences. Creating an Array in CFScript In this example, the ColdFusion ArrayNew() function is used to create an array within the CFScript block. This function initializes a new, empty array that can later ...