Passing Variables via the Query String - Exercise

Contact Us or call 1-877-932-8228
Passing Variables via the Query String - Exercise

Passing Variables via the Query String

Duration: 10 to 20 minutes.

In this exercise, you will write a script that says hello to different people based on what is passed through the query string.

  1. Open Basics/Exercises/HelloWho.html in your editor.
  2. Modify HelloWho.html so that each Beatle name is a link passing the name of that Beatle (Paul, John, George or Ringo) to HelloWho.cfm.
  3. Open Basics/Exercises/HelloWho.cfm in your editor.
  4. Modify HelloWho.cfm so that it outputs a greeting based on the link that is clicked on HelloWho.html.
  5. Test your solution in a browser.

Code Sample:

Basics/Exercises/HelloWho.html
<html>
<head>
	<title>Greeting the Beatles</title>
</head>
<body>
	Choose a Beatle to greet.
	<ul>
	<li><a href="HelloWho.cfm">Paul</a></li>
	<li><a href="HelloWho.cfm">John</a></li>
	<li><a href="HelloWho.cfm">George</a></li>
	<li><a href="HelloWho.cfm">Ringo</a></li>
	</ul>
</body>
</html>

Code Sample:

Basics/Exercises/HelloWho.cfm
<html>
<head>
	<title></title>
</head>
<body>

</body>
</html>

Change the links so that each Beatle gets a custom greeting (e.g, Howdy Paul, Hi John, Bye George, Hey Ringo).

Solution:

Basics/Solutions/HelloWho.html
<html>
<head>
	<title>Greeting the Beatles</title>
</head>
<body>
	Choose a Beatle to greet.
	<ul>
	<li><a href="HelloWho.cfm?beatle=Paul">Paul</a></li>
	<li><a href="HelloWho.cfm?beatle=John">John</a></li>
	<li><a href="HelloWho.cfm?beatle=George">George</a></li>
	<li><a href="HelloWho.cfm?beatle=Ringo">Ringo</a></li>
	</ul>
</body>
</html>

Solution:

Basics/Solutions/HelloWho.cfm
<cfoutput>
<html>
<head>
	<title>Hello #URL.beatle#!</title>
</head>
<body>
	Hello #URL.beatle#!
</body>
</html>
</cfoutput>

Challenge Solution:

Basics/Solutions/HelloWho-challenge.html
<html>
<head>
	<title>Greeting the Beatles</title>
</head>
<body>
	Choose a Beatle to greet.
	<ul>
		<li><a href="HelloWho-challenge.cfm?greet=Howdy&beatle=Paul">Paul</a></li>
		<li><a href="HelloWho-challenge.cfm?greet=Hi&beatle=John">John</a></li>
		<li><a href="HelloWho-challenge.cfm?greet=Bye&beatle=George">George</a></li>
		<li><a href="HelloWho-challenge.cfm?greet=Hey&beatle=Ringo">Ringo</a></li>
	</ul>
</body>
</html>

Challenge Solution:

Basics/Solutions/HelloWho-challenge.cfm
<cfoutput>
<html>
<head>
	<title>#URL.greet# #URL.beatle#!</title>
</head>
<body>
	#URL.greet# #URL.beatle#!
</body>
</html>
</cfoutput>
Next