By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

Passing values from a function generated html.

P: n/a
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="selected_gal=curr_gal;
make_frameset(selected_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(gallery_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#.html) 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.
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <41***************@blabla.com>,
cirillo_curiosone <ci***************@blabla.com> wrote:
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.
.... Thanks a lot in advance.


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.html">
<frame src="frame2.html">
<frame src="frame3.html" name="fill_me">
<frame scrolling=yes src="frame4.html">
<frame src="frame5.html">
<frame src="frame6.html" id="test">
<noframes>
Sorry, this document can be viewed only with a
frames-capable browser.
<a href="frame1.html">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.lastIndexOf('/');
alert("begin = " + lastLoc);
if (lastLoc > 0 )
{
var myName = document.URL.substring(lastLoc+1,document.URL.leng th);
alert("myName = " + myName);
var beginLoc = myName.indexOf('.');
alert("beginLoc = " + beginLoc);
if (beginLoc > 0 )
{
var myName = myName.substring(0,beginLoc);
// We name have the variable name.
alert("myName = " + myName);
var localCopy = parent.window[myName];
alert("localCopy = " + 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
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.