Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-20-2005, 06:31 PM   PM User | #1
eischech
New to the CF scene

 
Join Date: Mar 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
eischech is an unknown quantity at this point
passing JavaScript parameters to HTML

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>

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

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 --
eischech
eischech is offline   Reply With Quote
Old 03-20-2005, 06:57 PM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
something like this?
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
div {
text-align:center;
}
</style>
</head>

<body>
<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+'">');
document.write('<p>'+titl+'</p>');
</script></div>
</body>
</html>
_Aerospace_Eng_ is offline   Reply With Quote
Old 03-20-2005, 09:53 PM   PM User | #3
eischech
New to the CF scene

 
Join Date: Mar 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
eischech is an unknown quantity at this point
Smile

Like that. Thanks.

eischech
eischech is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:01 PM.


Advertisement
Log in to turn off these ads.