ColdFusion MX: From Static to Dynamic in 10 Steps

Team-Fly    

ColdFusion® MX: From Static to Dynamic in 10 Steps

By Barry Moore

Table of Contents
Step 2.  Using Variables

In this example, we are going to use two pages to demonstrate how to pass variables via a URL.

  1. Open your editor and type the code shown in Listing 2.2, or you can open the Page1.cfm file from the CompletedFiles\Examples\Step02 folder.

    Listing 2.2 Page1.cfm

    <!--- File: Page1.htm Description: Demonstrates passing URL variables Author: Created: ---> <HTML> <HEAD> <TITLE>Pick a color any color</TITLE> </HEAD> <BODY> <H2>What is your favorite color?</H2> <A HREF="Page2.cfm?Color=Blue">Blue</A><BR> <A HREF="Page2.cfm?Color=Red">Red</A><BR> <A HREF="Page2.cfm?Color=Green">Green</A><BR> <A HREF="Page2.cfm?Color=Yellow">Yellow</A> </BODY> </HTML>

  2. Save the file as Page1.htm into your Examples\Step02 folder.

  3. In your text editor create a new file and type the code shown in Listing 2.3, or you can open the Page2.cfm file from the CompletedFiles\Examples\Step02 folder.

    Listing 2.3 Page2.cfm

    <!--- File: Page2.cfm Description: Demonstrates the use of URL scope variables Author: Created: ---> <HTML> <HEAD> <TITLE>That is so cool</TITLE> </HEAD> <BODY> <H2>That is so cool!</H2> <H2><CFOUTPUT>#URL.Color# is my favorite too.</CFOUTPUT></H2> <A HREF="Page1.htm">&lt;&lt;back</A> </BODY> </HTML>

  4. Save the file as Page2.cfm into your Examples\Step02 folder.

  5. Open a browser and browse to Page1.htm. Your URL should be something similar to http://localhost/Examples/Step02/Page1.htm. You should see a page similar to the one shown in Figure 2.3.

    Figure 2.3. Page1.htm browser display.

  6. Follow any link on Page1.htm. Notice the URL variable present in the browser's address bar. You should see a page similar to the one shown in Figure 2.4.

    Figure 2.4. Page2.cfm browser display.

  7. The variable is pulled from the URL and is used in the <CFOUTPUT> statement.


    Team-Fly    
    Top
     

    Категории