How to create a modal Window in ColdFusion

cfwindow - create modal window

cfwindowModal.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfwindow tag: how to create modal window in coldfusion</title>
</head>

<body>
<h2 style="color:SaddleBrown; font-style:italic">cfwindow tag example: Modal Window</h2>
<hr width="400" align="left" color="CadetBlue" />
<br />

<cfwindow 
 name="FunnyWindow" 
    title="Funny Image" 
    initshow="true" 
    resizable="false"
    height="400" 
    width="450"
    modal="true"
    >
 <img src="Images/Funny.jpg" height="300" width="400"/>
</cfwindow>

</body>
</html>





More ColdFusion examples

How to use CFwindow in ColdFusion

cfwindow

cfwindow.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfwindow tag: how to use cfwindow in coldfusion</title>
</head>

<body>
<h2 style="color:DodgerBlue; font-style:italic">cfwindow tag example: how to use</h2>
<hr width="400" align="left" color="CadetBlue" />
<br />

<cfwindow 
 name="FlowerWindow" 
    title="Flower Image" 
    initshow="true" 
    modal="false" 
    resizable="false"
    height="450" 
    width="550"
    >
 <img src="Images/Flowers.gif"/>
</cfwindow>

</body>
</html>





More ColdFusion examples

How to use ColdFusion.navigate Ajax JavaScript Function

Ajax JavaScript Function - ColdFusion.navigate

ColdFusionnavigate.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax JavaScript Function: how to use ColdFusion.navigate in coldfusion</title>
</head>

<body>
<h2 style="color:DodgerBlue; font-style:italic">Ajax JavaScript Function example: ColdFusion.navigate</h2>
<hr width="500" align="left" color="PaleVioletRed" />
<br />

<a href="JavaScript:ColdFusion.navigate('PenguinImage.cfm','TestWindow')">Click for see Penguin image</a>
<br />
<a href="JavaScript:ColdFusion.navigate('DolphinImage.cfm','TestWindow')">Click for see Dolphin image</a>

<cfwindow name="TestWindow" title="ImageView" initshow="true">
 Test String.
</cfwindow>

</body>
</html>


PenguinImage.cfm


<img src="Images/Penguin.jpg" />


DolphinImage.cfm



<img src="Images/Dolphin.jpg" />













More ColdFusion examples

How to use ColdFusion.Window.create Ajax JavaScript Function

Ajax JavaScript Function - ColdFusion.Window.create

ColdFusionWindowcreate.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax JavaScript Function: how to use ColdFusion.Window.create in coldfusion</title>
</head>

<body>
<h2 style="color:Crimson; font-style:italic">Ajax JavaScript Function example: ColdFusion.Window.create</h2>
<hr width="600" align="left" color="CadetBlue" />
<br />

<cfajaximport tags="cfwindow">

<a href="JavaScript:ColdFusion.Window.create('CatWindow','Cat Image','CatImage.cfm')">
 <b>Click here for see Cat image</b>
</a>

</body>
</html>


CatImage.cfm


<img src="Images/Cat.jpg" />









More ColdFusion examples

How to create a Presentation in ColdFusion

Introduction

Creating presentations in ColdFusion can be a powerful way to dynamically display content within web applications. The <cfpresentation> tag in ColdFusion allows developers to create a series of slides that can contain text, images, or other media, similar to a PowerPoint presentation. This tutorial will guide you through using the <cfpresentation> tag to make an image-based presentation with a set duration for each slide. In the example provided, the code showcases how to create a presentation featuring images of a cat and a rat, each displayed on its own slide.

This tutorial will break down the code example to help you understand the structure and application of <cfpresentation> and <cfpresentationslide> tags, offering a step-by-step guide on styling, content placement, and defining timing for each slide.

Understanding the <cfpresentation> Tag

The <cfpresentation> tag serves as the main container for all slides in a ColdFusion presentation. It defines the overall presentation, including its title and structure. In the example, the title is set to "Image Viewer," establishing the theme for the presentation. This overarching container is essential, as it houses each individual slide, ensuring they display sequentially and adhere to the specified format.

Using <cfpresentation> allows developers to create web-based presentations that display directly in the browser, making them ideal for product showcases, tutorials, and image galleries.

Creating Individual Slides with <cfpresentationslide>

Each slide within a <cfpresentation> is created using the <cfpresentationslide> tag. In this example, two slides are included: one featuring a "Cat Image" and another with a "Rat Image." Each slide tag includes attributes like title and duration, which define the title displayed for that slide and the amount of time the slide remains visible.

For the "Cat Image" slide, the title is set to "Cat Image," and the duration to 10 seconds. This configuration ensures the viewer has adequate time to view each slide before it transitions to the next one. The slide’s title appears prominently, adding context to each image, while the duration helps control the pace of the presentation.

Adding Content and Styling to Slides

Within each <cfpresentationslide>, you can add various types of content. In this example, each slide contains an <h3> heading styled with color and italics to highlight the title in a visually appealing way. For the "Cat Image" slide, the color "DeepPink" is used for the title, while the "Rat Image" slide uses "Crimson," helping to distinguish each slide visually. This technique allows for easy customization of text and style, making each slide unique.

Each slide also includes an image element that displays an image from a specified file path. The images are stored in an "Images" folder, which ColdFusion references for display within the presentation. By pointing to external images, the presentation remains modular and easy to update, as images can be swapped out without altering the code structure.

Setting Up the Presentation Display and Timing

The <cfpresentationslide> tag’s duration attribute is crucial for setting up how long each slide will be displayed before advancing. Here, each slide is given a duration of 10 seconds. This timing setup is helpful for viewers who need a fixed amount of time to process each slide’s content before it moves to the next.

Adjusting the duration attribute is easy, allowing the presentation’s timing to be tailored based on the complexity or amount of content on each slide. This setup is beneficial for situations where slides contain text, detailed images, or information that may require more time to review.

Conclusion

The example above provides a straightforward way to create a dynamic, web-based presentation in ColdFusion using the <cfpresentation> and <cfpresentationslide> tags. By setting up a container for the presentation and defining each slide’s title, content, and duration, developers can create an engaging and time-controlled sequence that displays directly in a browser.

ColdFusion’s presentation functionality is particularly useful for showcasing image galleries, training slides, and informational content without needing additional software. Custom styling, flexible timing, and simple integration make <cfpresentation> a versatile tool for web developers looking to add interactive presentations to their projects.


cfpresentation.cfm

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfpresentation tag: how to use cfpresentation in coldfusion</title>
</head>

<body>

<cfpresentation title="Image Viewer">
 <cfpresentationslide title="Cat Image" duration="10">
        <h3 style="color:DeepPink; font-style:italic;">
   Cat Image        
        </h3>
     <img src="Images/Cat.jpg" />
    </cfpresentationslide>
 <cfpresentationslide title="Rat Image" duration="10">
        <h3 style="color:Crimson; font-style:italic;">
   Rat Image        
        </h3>
     <img src="Images/Rat.jpg" />
    </cfpresentationslide>
</cfpresentation>

</body>
</html>



More ColdFusion examples

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.FirstName[Counter]);
  WriteOutput("  ");
  WriteOutput(qEmployee.LastName[Counter]);
  WriteOutput("<br />");
  }
</cfscript>
</h3>

</body>
</html>





More ColdFusion examples

How to preserve data in a Form in ColdFusion

Introduction

In web development, preserving user data in form fields after a page reload or submission is a common challenge. ColdFusion offers an elegant way to handle this through the cfform tag's preservedata attribute. By enabling this feature, ColdFusion ensures that user-entered data remains intact even after submitting the form, providing a smoother and more user-friendly experience. This tutorial demonstrates how to use the preservedata attribute in ColdFusion forms and explains the core mechanics behind it.

This example illustrates how ColdFusion can manage form data, presenting a simple use case where a user enters their name and address. The form preserves the user's input and displays it back to them upon submission, ensuring the data remains visible without needing to refill the form fields after the page reloads.

Preserving Form Data with cfform

ColdFusion's cfform tag simplifies the creation of interactive forms with built-in support for preserving data. The preservedata attribute is the key element here, which, when set to "yes," automatically repopulates the form fields with the user's input after the form is submitted.

In this example, we define a form that collects two basic pieces of information: the user's name and address. Each field is created using the cfinput tag, which binds these inputs to the form. By setting preservedata="yes", ColdFusion ensures that if the page is refreshed or submitted, the form fields will retain the user’s input. This feature is particularly useful in scenarios where users need to review or correct their information after submitting the form.

Displaying the Submitted Data

After the form is submitted, the user’s input is processed and displayed back to them. The example utilizes a conditional cfif block to check if the form has been submitted by testing the existence of the Form.Submit variable. If the form has been submitted, ColdFusion uses cfoutput to display the user’s name and address dynamically.

This step enhances user interaction by confirming the data that has been submitted. The cfoutput block ensures that the submitted data is cleanly presented on the page, making it easy for users to verify what they have entered.

The Role of preservedata="yes"

The preservedata attribute in the cfform tag is central to this example. Without this attribute, after a form submission, the form fields would reset, causing the user’s input to disappear. This could lead to frustration if users need to make corrections or changes, forcing them to re-enter their information from scratch. By preserving the data, ColdFusion keeps the form's state consistent, enhancing the overall user experience.

This feature is especially beneficial in more complex forms or multi-step processes where users may need to navigate between different sections of a form without losing their previously entered data.

Conclusion

ColdFusion’s ability to preserve form data through the cfform tag's preservedata attribute offers a streamlined solution for managing user input. This functionality ensures that form fields maintain their values after submission, creating a more intuitive and efficient experience for users.

In this tutorial, we explored a basic example of preserving form data using cfform. By applying this feature, ColdFusion developers can easily enhance the usability of their forms, minimizing user frustration and reducing the need for redundant data entry. This simple yet powerful feature can be a valuable tool for improving form-driven applications in ColdFusion.


cfformPreserveData.cfm

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cffrom preservedata property: How to preserve data in coldfusion form</title>
</head>

<body>
<h2 style="color:DodgerBlue; font-style:italic">cfform example: preservedata property</h2>
<hr width="350" align="left" color="PaleVioletRed" />
<br />


<cfform name="testForm" method="post" preservedata="yes">
 <b>Name</b>
 <cfinput name="Name" type="text">
    <br />
 <b>Address</b>
    <cfinput name="Address" type="text">
    <br />
    <cfinput name="Submit" type="submit" value="Submit Data">
</cfform>

<h4 style="color:#F30;">
 <cfif IsDefined("Form.Submit")>
        <cfoutput>
            Your name: #Form.Name#
            <br />
            Address: #Form.Address#
        </cfoutput>
    </cfif>
</h4>
</body>
</html>













More ColdFusion examples

How to upload only image file in coldfusion

cffile - upload only image file

cffileUploadImge.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cffile tag: how to upload only image file in coldfusion</title>
</head>

<body>
<h2 style="color:DodgerBlue; font-style:italic">cffile example: Upload Image</h2>
<hr width="350" align="left" color="PaleVioletRed" />

<cfset UploadFolder="C:\UploadImage">

<h3 style="color:DeepPink; font-style:italic;">
<cfoutput>
<cfif DirectoryExists(UploadFolder)>
 <cfif IsDefined("Form.UploadFile") AND Form.UploadFile NEQ "">
     <cftry>
            <cffile 
                action="upload" 
                filefield="UploadFile" 
                destination="#UploadFolder#" 
                nameconflict="overwrite"
                accept="image/*"
                >
                File uploaded successfully!
                <br />
                Uploaded file: #cffile.ClientFile#
            <cfcatch type="any">
                Error: #cfcatch.Message#
            </cfcatch>
     </cftry>
    <cfelse>
        Select a file first!        
    </cfif>
<cfelse>
 Upload Directory not exists    
</cfif>
</cfoutput>
</h3>


<form name="UploadForm" method="post" enctype="multipart/form-data" action="">
 <input type="file" name="UploadFile">
    <input type="submit"  name="submit" value="Upload"/>
</form>

</body>
</html>


















More ColdFusion examples

asp.net - How to change Panel horizontal align programmatically

Change Panel horizontal alignment programmatically
The Panel represents a control that acts as a container for other controls. The Panel is especially useful when the asp.net developers want to generate controls programmatically, hide and show a group of controls, or localize a group of controls. The Panel’s Direction property is used to display text in the Arabic language.

The following asp.net c# tutorial code demonstrates how we can change the horizontal alignment of a Panel web server control. Here we change the Panel’s horizontal alignment to center and right programmatically. In the below code example, we used the Panel control’s HorizontalAlign property to change its horizontal alignment programmatically.

The Label HorizontalAlign property gets or sets the horizontal alignment of the contents within the panel. The HorizontalAlign property value is one of the HorizontalAlign values. The default value of this property is NotSet.

The HorizontalAlign enumerator value specifies the horizontal alignment of items within a container. Its Center value ensures the contents of a container are centered. And the Right value ensures the contents of a container are right justified.

The Label HorizontalAlign property throws ArgumentOutOfRangeException if the horizontal alignment is not one of the HorizontalAlign values. So finally, here we used the Panel’s HorizontalAlign value to HorizontalAlign.Right to set its horizontal alignment to right and HorizontalAlign.Center to set its horizontal alignment to the center.
PanelHorizontalAlign.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Panel1.HorizontalAlign = HorizontalAlign.Right;

    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        Panel1.HorizontalAlign = HorizontalAlign.Center;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change Panel horizontal align programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">Panel Example: HorizontalAlign</h2>
        <asp:Panel 
             ID="Panel1"
             runat="server"
             Height="150"
             Width="400"
             BorderWidth="2"
             Font-Size="X-Large"
             Font-Bold="true"
             ForeColor="Olive"
             BackColor="Beige"
             BorderColor="DarkOliveGreen"
             >
             <br />
             HorizontalAlign
        </asp:Panel>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="SeaGreen"
             Text="Panel HorizontalAlign Right"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server"
             ForeColor="SeaGreen"
             Text="Panel HorizontalAlign Center"
             Height="45"
             OnClick="Button2_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>

asp.net - How to show and hide a Panel programmatically

Show (visible) and hide Panel programmatically
The Panel is an asp.net web server control that acts as a container control for other asp.net controls and HTML elements. Panel inside controls act as a group of controls. So we can apply common properties of the Panel's inside controls by setting the panel's properties such as showing or hiding all controls, aligning and directing controls, etc.

Panel Visible property accepts a Boolean value. if we set the Panel Visible property value to false then it hides all inside controls from the web page with the Panel itself. Panel Visible property value True means the Panel and its inside controls will render in web pages and all elements are visible to visitors.

We can control the Panel and its inside controls visibility using Panel's Visible property. The Visible property value True and False works as a switch to rendering or not rendering the Panel on the web page. The Panel acts as a parent control and the inside control as a child control.

The following asp.net c# example code demonstrates to us how can we show or hide panel server control programmatically on a web page.
PanelVisible.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Panel1.Visible = false;
        Label1.Text = "Panel now hide";

    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        Panel1.Visible = true;
        Label1.Text = "Panel now visible";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to show, hide, visible Panel programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">Panel Example: Show Hide</h2>
        <asp:Label 
             ID="Label1"
             runat="server"
             ForeColor="SeaGreen"
             Font-Size="Large"
             Font-Bold="true"
             Font-Italic="true"
             >
        </asp:Label>
        <br /><br />
        <asp:Panel 
             ID="Panel1"
             runat="server"
             Height="150"
             Width="350"
             HorizontalAlign="Center"
             ForeColor="Snow"
             BackColor="DeepPink"
             Font-Size="X-Large"
             >
             <br /><br />
             Panel Visible property
        </asp:Panel>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="DarkMagenta"
             Text="Hide Panel"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server"
             ForeColor="DarkMagenta"
             Text="Visible Panel"
             Height="45"
             OnClick="Button2_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>

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

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

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

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

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>






More ColdFusion examples

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){
   case "Crimson":
    WriteOutput("Crimson is red type color");
    break;
   case "DodgerBlue":
    WriteOutput("Crimson is blue type color");
    break;
   case "SeaGreen":
    WriteOutput("Crimson is green type color");
    break;
   default:
    WriteOutput("You input an unknown color.");
   }
 }
</cfscript>

</body>
</html>













More ColdFusion examples

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

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 ");
   WriteOutput(Form.UserName); 
  }
  else
   WriteOutput("Please input your name");
  }
</cfscript>

</body>
</html>













More coldfusion examples

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

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 be populated with data. The parameter 1 passed to ArrayNew() indicates that a single-dimensional array is being created.

Single-dimensional arrays are commonly used when you need to store a list of items, such as the list of colors seen in this example. The use of CFScript syntax here is preferable for developers who are familiar with other scripting languages, making it easier to transition between different environments.

Populating the Array

Once the array is initialized, the next step is to populate it with data. In this case, the ArrayAppend() function is used to add elements to the array. This function appends a new value at the end of the array. The color values like "Crimson", "Red", "SeaGreen", and "OrangeRed" are successively added, creating a list of color names.

The use of ArrayAppend() is straightforward, allowing developers to add as many elements as needed. This function returns a boolean value indicating whether the operation was successful, but in this example, the return value is stored in a temporary variable (temp), which is not used further. This technique keeps the code clean and focuses on the core task of building the array.

Displaying the Array

Once the array is populated, it can be displayed to the user. In this example, the ColdFusion tag cfdump is used to output the contents of the array in a readable format. The cfdump tag is often employed during development to quickly inspect variables and data structures, offering a visual representation of the array and its elements.

Before dumping the array, the code uses the IsDefined() function to ensure that the array has been successfully created. This conditional check helps avoid errors that might occur if the array was not properly initialized or populated.

Conclusion

This example illustrates the simplicity and efficiency of working with arrays in ColdFusion's CFScript. By using CFScript to create and manipulate arrays, developers can write cleaner and more readable code that is easier to maintain. The process of initializing an array, appending elements, and displaying the data is made intuitive with functions like ArrayNew() and ArrayAppend().

Understanding how to use arrays effectively is crucial for handling collections of data in ColdFusion applications. By leveraging CFScript, developers can take advantage of a scripting-style syntax that simplifies the management of arrays and other data structures. This approach not only enhances code readability but also improves performance in dynamic web applications.


cfscriptArray.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 array in cfscript</title>
</head>

<body>
<h2 style="color:DodgerBlue; font-style:italic">cfscript example: Array</h2>
<hr width="350" align="left" color="PaleVioletRed" />
<br />

<cfscript>
 ColorArray = ArrayNew(1);
 temp = ArrayAppend(ColorArray,"Crimson");
 temp = ArrayAppend(ColorArray,"Red");
 temp = ArrayAppend(ColorArray,"SeaGreen");
 temp = ArrayAppend(ColorArray,"OrangeRed");
</cfscript>

<cfif IsDefined("ColorArray")>
 <cfdump var="#ColorArray#">
</cfif>

</body>
</html>





More ColdFusion examples

How to change menu static item hover style in asp.net c#

Static hover style in menu control
The Menu is an ASP.NET web server control. Menu control's StaticHoverStyle property gets a reference to the style object that allows us to set the appearance of a static menu item when the mouse pointer is positioned over it. This property value type is System.Web.UI.WebControls.Style. This Style represents the style of a static menu item when the mouse pointer is positioned over it.

The StaticHoverStyle property has a few sub-properties. we can set the property both declaratively and programmatically. The declarative syntax is Property-Subproperty and the programmatic syntax is Property.Subproperty (StaticHoverStyle.BackColor). So we can set the static menu item hover style as setting the background color, text color, border style, border width, font name, text size, etc.

The following ASP.NET C# example code demonstrates to us how can we set or change the Menu control's static menu items hover style programmatically at run time in an ASP.NET application.
MenuStaticHoverStyle.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Menu1.StaticHoverStyle.BackColor = Color.Crimson;
        Menu1.StaticHoverStyle.ForeColor = Color.Snow;
        Menu1.StaticHoverStyle.Font.Size = FontUnit.Large;
        Menu1.StaticHoverStyle.Font.Name = "Comic Sans MS";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change static hover style in Menu control programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">Menu Example: StaticHoverStyle</h2>
        <asp:SiteMapDataSource 
             ID="SiteMapDataSource1" 
             runat="server"
             />
        <div style="height:150px">
            <asp:Menu 
                 ID="Menu1" 
                 runat="server" 
                 DataSourceID="SiteMapDataSource1"
                 StaticDisplayLevels="2"
                 ForeColor="MediumSeaGreen"
                 Font-Bold="true"
                 >
            </asp:Menu>
        </div>
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="SaddleBrown"
             Text="Change StaticHoverStyle"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>
Web.sitemap
Web.sitemap source code here.   

How to use cfdiv in ColdFusion

Introduction

In web development, user interactions often require dynamic content updates without needing to reload the entire page. Adobe ColdFusion provides a useful tool for this through the cfdiv tag, which allows developers to refresh specific sections of a webpage asynchronously, improving user experience by reducing unnecessary page loads. This tutorial demonstrates how to use the cfdiv tag in ColdFusion, providing a simple form that takes user input and dynamically displays a response.

This example comprises two main components: an HTML page that incorporates ColdFusion's cfdiv and cfform elements, and a separate ColdFusion file (hello.cfm) that processes user input and dynamically returns content based on it. By the end of this tutorial, you'll understand how to use cfdiv for smooth user interactions, powered by ColdFusion’s binding features.

Structure of the Main HTML Page

The main HTML page (cfdiv.cfm) forms the front-end of this example. It begins with a standard HTML structure, including a <head> section that sets the document type and meta information like character encoding. Within the body of the page, a header (<h2>) with an eye-catching style is displayed to introduce the ColdFusion cfdiv tag example.

The core of the user interaction takes place in a ColdFusion form (cfform), which allows the user to input their name via a text field (cfinput). The cfinput field is bound to a variable, UserName, which is later used in the dynamic content loading process. The ColdFusion form doesn’t handle the submission in a traditional way; instead, it works hand-in-hand with the cfdiv tag to dynamically update a portion of the page.

The cfdiv Tag and Dynamic Binding

The cfdiv tag is the centerpiece of this tutorial. This tag creates a division (<div>) on the page that gets its content from an external source—in this case, the hello.cfm file—based on the value entered by the user. The cfdiv tag is used with an id attribute (HelloDiv) to identify the section of the page that will be updated.

The real power of the cfdiv lies in its bind attribute. In this example, the bind attribute is used to link the user’s input to the ColdFusion component that dynamically generates content. Specifically, the bind="url:hello.cfm?Name={UserName}" expression binds the value of the UserName input field to a URL parameter (Name) in the hello.cfm file. Whenever the user types something in the input field, the cfdiv sends an asynchronous request to hello.cfm and updates the content within the HelloDiv element based on the response.

Processing Logic in hello.cfm

The hello.cfm file handles the logic behind the dynamic content display. It checks whether the Name URL parameter is defined using the IsDefined() function. If the parameter is not provided, no content is returned. If the parameter is defined but the value is empty, the system prompts the user to "Input your name!"

If the user has provided a valid name, hello.cfm responds with a personalized message. This is done using the cfoutput tag, which dynamically displays a greeting along with the user’s name in a styled format. The conditional checks ensure that the response is contextual and user-friendly.

User Interaction Flow

When the user types their name into the text field, ColdFusion dynamically updates the cfdiv with a personalized greeting or a prompt asking for input. This process is seamless because the page doesn’t refresh—instead, only the content inside the cfdiv changes, giving the appearance of an interactive, real-time response.

Conclusion

The example demonstrates how to use ColdFusion's cfdiv tag to create dynamic, responsive user interfaces that load content asynchronously without a full page refresh. By leveraging the bind attribute, developers can easily tie form inputs to server-side logic, enabling more interactive web applications. In this case, the example shows a simple yet powerful use of ColdFusion to create a personalized user experience.

The cfdiv tag is an excellent tool for enhancing the performance and interactivity of your ColdFusion applications, particularly when combined with ColdFusion forms and conditional logic. Whether you're building a simple feedback form or a more complex dynamic application, cfdiv can streamline user interactions and reduce server load by only updating parts of the page as needed.


cfdiv.cfm

<!DOCTYPE html">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfdiv tag example: how to use cfdiv tag in coldfusion</title>
</head>

<body>
<h2 style="color:DodgerBlue">ColdFusion cfdiv tag example</h2>

<cfform name="HelloForm">
 Your Name: 
 <cfinput type="text" name="UserName">
</cfform>

<cfdiv id="HelloDiv" bind="url:hello.cfm?Name={UserName}">

</body>
</html>


hello.cfm

<cfif IsDefined("url.Name")>
 <cfif url.Name eq "">
     Input your name!
 <cfelse>
     <cfoutput><h2 style="color:Crimson">Hi <i>#url.Name#</i>!</h2></cfoutput>
    </cfif>
</cfif>













More ColdFusion examples

ColdFusion - How to catch exception and handle error

cftry and cfcatch - catch exception and handle error

cftry.cfm


<!DOCTYPE html">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cftry and cfcatch tag example: how to catch exception and handle error</title>
</head>

<body>
<h2 style="color:DodgerBlue">ColdFusion cftry and cfcatch example</h2>

<cftry>
 <!---Here i input wrong table name--->
 <cfquery name="qEmployee" datasource="cfdocexamples">
     SELECT * FROM Employeess
    </cfquery>
    <cfdump var="#qEmployee#">

    <cfcatch type="any">
  <cfoutput>
         Error occured....<br /><br />
         Message: <b>#cfcatch.Message#</b><br />
            Detail: <b>#cfcatch.Detail#</b><br />
            Type: <b>#cfcatch.Type#</b><br />
  </cfoutput>
    </cfcatch>
</cftry>

</body>
</html>





More ColdFusion examples

asp.net - Change TreeView root node style programmatically

Change TreeView root node style programmatically
The TreeView is an asp.net web server control. The TreeView is located under System.Web.UI.WebControls namespace. TreeView web server control displays hierarchical data. Such as a table of contents in a tree structure.

The following asp.net c# tutorial code demonstrates how we can programmatically change the TreeView web server control’s root node style. The asp.net c# developers can set the TreeView root node style using its RootNodeStyle property.

The TreeView RootNodeStyle property gets a reference to the TreeNodeStyle object that allows us to set the appearance of the root node in the TreeView control. The TreeView RootNodeStyle property value is TreeNodeStyle which is a reference to the TreeNodeStyle that represents the style of a node in the TreeView.

The TreeNodeStyle class represents the style of a node in the TreeView control. The TreeView RootNodeStyle property controls the default appearance of the root node in the TreeView control.

In this asp.net c# tutorial, we changed the TreeView root node’s various styles such as background color, text color, border color, border width, and font style bold and italic using its RootNodeStyle property.
TreeViewRootNodeStyle.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        TreeView1.RootNodeStyle.BackColor = Color.Crimson;
        TreeView1.RootNodeStyle.ForeColor = Color.Snow;
        TreeView1.RootNodeStyle.BorderWidth = 1;
        TreeView1.RootNodeStyle.BorderColor = Color.HotPink;
        TreeView1.RootNodeStyle.Font.Bold = true;
        TreeView1.RootNodeStyle.Font.Italic = true;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change TreeView root node style programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy">TreeView Example: RootNodeStyle</h2>
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
        <asp:TreeView 
             ID="TreeView1"
             runat="server"
             DataSourceID="SiteMapDataSource1"
             Width="275"
             BorderWidth="2"
             BorderColor="Crimson"
             >
        </asp:TreeView>
        <br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="Crimson"
             Text="Change RootNodeStyle"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>
Web.sitemap
Web.sitemap source code here.   

asp.net - Change TreeView node style programmatically

Change TreeView node style programmatically
The TreeView is an asp.net web server control. The TreeView is located under System.Web.UI.WebControls namespace. TreeView web server control displays hierarchical data. Such as a table of contents in a tree structure.

The following asp.net c# tutorial code demonstrates how we can programmatically change the TreeView web server control’s node style. The asp.net c# developers can set the TreeView node style using its NodeStyle property.

The TreeView NodeStyle property gets a reference to the TreeNodeStyle object that allows us to set the default appearance of the nodes in the TreeView control. The TreeView NodeStyle property value is TreeNodeStyle which is a reference to the TreeNodeStyle that represents the default style of a node in TreeView.

The TreeNodeStyle class represents the style of a node in the TreeView control. The TreeView NodeStyle property controls the default appearance of a node in the TreeView control.

In this asp.net c# tutorial, we changed the TreeView node’s various styles such as background color, text color, border color, border width, and font style using its NodeStyle property.
TreeViewNodeStyle.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        TreeView1.NodeStyle.BackColor = Color.LightPink;
        TreeView1.NodeStyle.ForeColor = Color.Crimson;
        TreeView1.NodeStyle.BorderWidth = 1;
        TreeView1.NodeStyle.BorderColor = Color.AliceBlue;
        TreeView1.NodeStyle.Font.Italic = true;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change TreeView node style programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy">TreeView Example: NodeStyle</h2>
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
        <asp:TreeView 
             ID="TreeView1"
             runat="server"
             DataSourceID="SiteMapDataSource1"
             Width="275"
             BorderWidth="2"
             BorderColor="Tomato"
             BackColor="HotPink"
             ForeColor="Snow"
             >

        </asp:TreeView>
        <br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="DarkBlue"
             Text="Change TreeView NodeStyle"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>
Web.sitemap
Web.sitemap source code here.   

asp.net - Change TreeView leaf node style programmatically

TreeView leaf node style programmatically
The TreeView is an asp.net web server control. The TreeView is located under System.Web.UI.WebControls namespace. TreeView web server control displays hierarchical data. Such as a table of contents in a tree structure.

The following asp.net c# tutorial code demonstrates how we can programmatically change the TreeView web server control’s leaf node style. The asp.net c# developers can set the TreeView leaf node style using its LeafNodeStyle property.

The TreeView LeafNodeStyle property gets a reference to the TreeNodeStyle object that allows you to set the appearance of leaf nodes. The TreeView LeafNodeStyle property value is TreeNodeStyle which is a reference to the TreeNodeStyle that represents the style of the leaf nodes in the TreeView.

The TreeNodeStyle class represents the style of a node in the TreeView control. The TreeView control allows us to specify different style characteristics such as font size and color for each of the different node types.

In this asp.net c# tutorial, we changed the TreeView leaf node’s various styles such as background color, text color, border color, border width, and font style using its LeafNodeStyle property.
TreeViewLeafNodeStyle.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        TreeView1.LeafNodeStyle.BackColor = Color.Crimson;
        TreeView1.LeafNodeStyle.ForeColor = Color.Snow;
        TreeView1.LeafNodeStyle.BorderWidth = 1;
        TreeView1.LeafNodeStyle.BorderColor = Color.HotPink;
        TreeView1.LeafNodeStyle.Font.Italic = true;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change TreeView leaf node style programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Green">TreeView Example: LeafNodeStyle</h2>
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
        <asp:TreeView 
             ID="TreeView1"
             runat="server"
             DataSourceID="SiteMapDataSource1"
             Width="250"
             >
        </asp:TreeView>
        <br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="DodgerBlue"
             Text="Change LeafNodeStyle"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>
Web.sitemap
Web.sitemap source code here.