Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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>

  • #3
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Like that. Thanks.

    eischech


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •