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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing a variable as dynamic source for a frame

    Hi all,

    I am fairly new to javascript programming, and this one has me stumped.

    I have page1.htm, which has 9 links on it. The destination URL for these links is page2.htm and I am appending a variable onto the end of the URL with the number of the link that is clicked. So the destination URL for link 1 is page2.htm?linknum=1.

    On page2.htm, I am grabbing the variable linknum from the URL and storing the value of the linknum in a variable called dest. I know variable dest contains the correct value because I can use a document.write statement to output it to the screen, and it's correct based on which link I clicked on page1.htm.

    Now, what I want to do is to use variable dest as the source for one of my frames. So here's the shell code:

    <html>
    <head>
    <!-- script goes here to grab linknum from the URL,
    and assign the value of linknum to variable dest.
    //-->
    </head>
    <frameset rows="25%,75%">
    <frame src="http://www.yahoo.com" id="frm1">
    <frame src= [insert variable dest here] id="frm2">
    </frameset>
    </html>

    I can't seem to make the [insert variable dest here] portion work to source the bottom frame, no matter what I try. If I don't hardcode the src value, the frame doesn't render at all. Can someone tell me what I may be doing wrong, and provide guidance to how I may accomplish this?

    Thanks!

  • #2
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,064
    Thanks
    0
    Thanked 15 Times in 15 Posts
    What is the code you are using to insert your value?

    <frame src=[insert variable dest here] id="frm2">

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #3
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Sage,

    Well, I asked someone else for help, and this was their suggestion:

    <html>
    <head>
    <!-- script goes here to grab linknum from the URL,
    and assign the value of linknum to variable dest.
    //-->
    <script language="javascript">
    <!-- hide from older browsers
    function setSrc()
    {
    document.frames[1].src=dest;
    }
    //-->
    </script>
    </head>
    <frameset rows="25%,75%" onLoad="setSrc();">
    <frame src="http://www.yahoo.com" id="frm1">
    <frame src="http://www.google.com" id="frm2">
    </frameset>
    </html>

    This code loads the two frames with yahoo.com and google.com, and gives me a javascript error of "permission denied", which I am assuming is referring to the setSrc() function. Any suggestions on how I can get this to work?

    Thanks!

  • #4
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,064
    Thanks
    0
    Thanked 15 Times in 15 Posts
    Ok,

    How is your linknum variable calling the source for your frame? Is the linknum the name of the document or is it referrencing a list?

    When you said you did a document.write and were able to get your variable did it appear in the format you wanted?

    What you may ultimately have to do is make a complete document.write for the frameset:
    Code:
    <HTML>
    <SCRIPT LANGUAGE="JavaScript">
    document.write("<frameset rows=25%,75%>");
    document.write("<frame src=http://www.yahoo.com id=frm1>");
    document.write("<frame src=" + dest + " id=frm2>");
    document.write("</frameset>");
    </SCRIPT>
    <NOFRAMES>
    <BODY BGCOLOR="#000000" TEXT="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000">
    </BODY>
    </NOFRAMES>
    </HTML>
    HTH,

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #5
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, Sage.

    I ended up just doing a document.write for the entire frameset as you suggested, and it worked perfectly. Thanks for guiding me in that route!

    Best regards,
    Richard


  •  

    Posting Permissions

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