
Passing Parameters: Loading a Selected Image in a Boilerplate Page
This page shows you how to pass a parameter to another Web page. In this example, the user clicks an image, and then a full-size version of the selected image is loaded into a boilerplate page.
Try it out:
Click an image to load the full-size version:
To pass data to another page, all you have to do is add a question mark (?) and the data to the end of the HREF attribute in a link. The images above link to boilerplate.asp. So to send the filename win95pre-full.jpg to that page, I set up my <A> tag like so:
<A HREF="boilerplate.asp?win95pre-full.jpg">
This means that the
browser loads the boilerplate.asp file, but it also specifies the extra data in the URL. We can then use
a short chunk of JavaScript code to extract the image name and load it. Here's the code I use in the
boilerplate.asp file:
<script language="JavaScript" type="text/javascript"">
<!--
//
// Make sure there's some data
//
if (location.search) {
//
// Extract the name of the graphics file
//
var image_filename = location.search.substring(1)
//
// Write the <IMG> tag using the name of the graphics
// file (you may need to adjust the SRC text)
//
document.write('<IMG SRC="/graphics/' + image_filename + '">')
}
//-->
</script>
Copyright © 1995-2008 Paul McFedries and Logophilia Limited
|