View Full Version : passing JavaScript parameters to HTML

03-20-2005, 07:31 PM
I know how to pass information from one HTML program to another via the URL, and how to use window.location.search to pull that information into JavaScript variables. But I don't know how to use those variables to dynamically change the HTML in the second program.

I need to select from a large pool of images and display the selected image in a secondary window. Now, I have a "display program" for each image. All the display programs are the same except for the image's filename and title. Changing the general display format, such as background color or some standardized text that accompanies every image, requires changing each display program. It's cut-&-paste, but still uses a lot of time. I'd rather have a single display program which I can call with a small program for each image that feeds the filename and title into the display code, like feeding parameters into a subprogram. That means getting the filename and title into the display program's <img src= > line. Can I do that with JavaScript? And if so, how?

Putting it another way -- once I bring the information into JS variables, I know how to write the HTML line. E.g.:

<script language="JavaScript">
<!-- Hide
var pic="thispicture.jpg";
var titl="This picture's title";

<script language="JavaScript">
<!-- Hide
document.writeln('<img src="image_directory/' +pic+'"');

But that writes the code out to the screen, not into the active HTML. What I want is something like the following (I know this won't work, but it illustrates what I'm after):

<img src="image_directory/ +pic ">
<p> +titl </p>

Any ideas?

Thanks --

03-20-2005, 07:57 PM
something like this?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
div {

<div>The image and text appear where you put the document.write script</div>
<div><script type="text/javascript">
var pic="thispicture.jpg";
var titl="This picture's title";
document.write('<img src="image_directory/'+pic+'">');

03-20-2005, 10:53 PM
Like that. Thanks. :)