• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Step 10. Using Lists, Arrays, and Struct... > Example 10.1: Creating, Passing, and...

Example 10.1: Creating, Passing, and Displaying a List

In this example, we will create the list on one page and pass it to another using a URL variable. The second page will use this list to build a drop-down menu.

1.
Open your text editor and type the code in Listing 10.1 or you can open the List1.cfm file from the CompletedFiles\Examples\Step10 folder.
Listing 10.1. List1.cfm

<!---
File:             List1.cfm 
Description:      Demo the use of list variable 
Author: 
Created: 
---> 
<!--- create the list ---> 
<CFSET lDepts="Marketing,Operations,Sales,Technology"> 

<HTML> 
  <HEAD> 
      <TITLE>Create The List</TITLE> 
  </HEAD> 
  <BODY> 
      <P>We have created a list with four elements. 
      Follow the link to pass this list to another page.</P> 

      <P>The List looks like this:</P> 
      <!--- output the list ---> 
      <P><CFOUTPUT>#lDepts#</CFOUTPUT></P> 

      <P><CFOUTPUT><A HREF="List2.cfm?list=#lDepts#">Next Page</A></CFOUTPUT></P> 
  </BODY> 
</HTML>

					  



2.
Save the file as List1.cfm in your Examples\Step10 folder.

3.
Now we will create the page with the drop-down menu. Open your text editor and type the code in Listing 10.2 or you can open the List2.cfm file from the CompletedFiles\Examples\Step10 folder.

Listing 10.2. List2.cfm

<!---
File:             List2.cfm 
Description:      Demo the use of list variable 
Author: 
Created: 
---> 
<HTML> 
  <HEAD> 
      <TITLE>Create The List</TITLE> 
  </HEAD> 
  <BODY> 
      <P>Use the list passed for the previous page to create a drop- down menu.</P> 
      <!--- loop through the list to create the menu ---> 
      <FORM> 
            <SELECT NAME="DeptMenu"> 
                  <CFLOOP INDEX="x" LIST="#URL.List#"> 
                    <CFOUTPUT> 
                        <OPTION VALUE="#x#" SELECTED>#x#</OPTION> 
                    </CFOUTPUT> 
                  </CFLOOP> 
            </SELECT> 
      </FORM> 
      <P>If you store the list in the Server, Application, or Session scope,<BR> you will be able to access the list from any page without having to manually<BR> pass the variable from page to page.</P> 
  </BODY> 
</HTML>

					  

4.
Save the file as List2.cfm in your Examples\Step10 folder.

5.
Browse to the Examples\Step10\List1.cfm page. You should see something similar to Figure 10.1.

Figure 10.1. The List1.cfm browser display.


6.
Follow the link to List2.cfm. You should see something similar to Figure 10.2.

Figure 10.2. The List2.cfm browser display.



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint