Passing values from a function generated html.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cirillo_curiosone

    #1

    Passing values from a function generated html.

    Hi,

    i'm new to javascript. I started studing it on the web few weeks ago,
    but still haven't been able to solve one big problem: HOT TO PASS VALUES
    FROM A SCRIPT VARIABLE TO A CHILD HTML GENERATED BY FUNCTION.

    Here'e the point:

    I'm writing a simple website for showing my photographs. It has a
    central page with many links (as many as galleries are).
    I thought to built the main page with a for-loop in the following way:

    for loop ...
    (
    document.write( ' <a onClick="select ed_gal=curr_gal ;
    make_frameset(s elected_gal)">' );
    document.write( ' <img src="../Images/gal_'+curr_gal+ '_tn.jpg"
    width="120" height="120" border="0">');
    document.write( ' </a><br>');
    )


    The function make_frameset is based on the following commands:

    <script type="text/javascript">
    function make_frameset(g allery_num)
    {
    ....
    document.write( '<frameset rows="90,360,90 ">');
    document.write( ' <frame name="frame1" src="./gal_frame1.html ">');
    document.write( ' <frame name="frame2" src="./gal_frame2.html ">');
    document.write( ' <frame name="frame3" src="./gal_frame3.html "
    target="frame2" >');
    document.write( ' <noframes><body ></body></noframes>');
    document.write( '</frameset>');
    ....
    }
    </script>

    Here's the problem: i haven't been able, right now, to pass the
    gallery_num parameter to the child frames (gal_frame#.htm l) files.
    How can i get that value from there? I tried with parent.gallery_ num,
    but failed.

    This is quite important, as it would allow me to use just one html
    source for each gallery, with a selection parameters for accessing the
    corresponding images.

    Thanks a lot in advance.


  • Robert

    #2
    Re: Passing values from a function generated html.

    In article <4104A9CE.34626 63E@blabla.com> ,
    cirillo_curioso ne <cirillo_curios one@blabla.com> wrote:
    [color=blue]
    > Hi,
    >
    > i'm new to javascript. I started studing it on the web few weeks ago,
    > but still haven't been able to solve one big problem: HOT TO PASS VALUES
    > FROM A SCRIPT VARIABLE TO A CHILD HTML GENERATED BY FUNCTION.
    >[/color]
    ....[color=blue]
    > Thanks a lot in advance.[/color]

    I believe these HTML files show one method of passing a variable to a
    child html file.

    The line:
    alert("from parent var picture1 =" + parent.frame1);
    shows how you can access a variable in the parent file.

    What I do in frame1.html is to generalize the code so all the child html
    files can be the same. I use the file name of the html file to look for
    a variable in the parent. I assume all the file names will be
    different.

    I tested this in Netscape 7.1 on MacOS 10.2.6.

    Here is frames.html which is the parent.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Frames Layout</title>

    <SCRIPT type="text/javascript">

    var frame1 = "picture 1";

    </script>

    </head>

    <frameset rows="60%,*" cols="65%,20%,* ">
    <frame src="frame1.htm l">
    <frame src="frame2.htm l">
    <frame src="frame3.htm l" name="fill_me">
    <frame scrolling=yes src="frame4.htm l">
    <frame src="frame5.htm l">
    <frame src="frame6.htm l" id="test">
    <noframes>
    Sorry, this document can be viewed only with a
    frames-capable browser.
    <a href="frame1.ht ml">Take this link</a>
    to the first HTML documetn in the set.
    </noframeset>
    </frameset>
    </html>
    Here is frame1.html

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Frame 1</title>
    <SCRIPT type="text/javascript">
    function nowRun()
    {
    // Access a variable in the parent's global name space
    alert("from parent var picture1 =" + parent.frame1);

    // Since we want all the children to have the same code, we
    // base the variable access off of the name of the html file.
    alert("working with document.url of " + document.URL);
    var lastLoc = document.URL.la stIndexOf('/');
    alert("begin = " + lastLoc);
    if (lastLoc > 0 )
    {
    var myName = document.URL.su bstring(lastLoc +1,document.URL .length);
    alert("myName = " + myName);
    var beginLoc = myName.indexOf( '.');
    alert("beginLoc = " + beginLoc);
    if (beginLoc > 0 )
    {
    var myName = myName.substrin g(0,beginLoc);
    // We name have the variable name.
    alert("myName = " + myName);
    var localCopy = parent.window[myName];
    alert("localCop y = " + localCopy);
    }

    }
    }
    </script>
    </head>

    <body onload="nowRun( );">
    <p>This is frame 1.</p>
    </body>
    </html>

    Here is frame6.html all the other frame documents are similar.

    !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Frame 6</title>

    </head>

    <body>
    <p>This is frame 6.</p>
    </body>
    </html>


    Robert

    Comment

    Working...