Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > Adobe ColdFusion

  • Print
  • + Share This
This chapter is from the book

Example 2.2: Passing Variables Via the URL

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.

  2. 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>
  3. Save the file as Page1.htm into your Examples\Step02 folder.

  4. 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.

  5. 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>
  6. Save the file as Page2.cfm into your Examples\Step02 folder.

  7. 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.

  8. Figure 2.3Figure 2.3 Page1.htm browser display.

  9. 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.

  10. Figure 2.4Figure 2.4 Page2.cfm browser display.

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

  • + Share This
  • 🔖 Save To Your Account