473,388 Members | 977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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="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
1 2381
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kie | last post by:
hello, when i create elements and want to assign events to them, i have realised that if the function assigned to that element has no parameters, then the parent node values can be attained. ...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
6
by: Jerry Camel | last post by:
Basic Web Form... A few text boxes and a checkbox - and a card reader... The effect I want to accomplish is this: The basic credit card fields are there and can be filled out. But if the user...
12
by: Dennis D. | last post by:
Hello: I want a function to return three variables to the calling procedure: Private Function CalcTimes(ByVal iAddDays as Integer, ByVal iAddHours as Integer, ByVal iAddMins as Integer) As...
1
by: | last post by:
Hi, 1st, I did a search and could not find any info on this, the Google results were good, but I'm still have issues...So any help will be great. I have a frame page, which contains 3 frames...
4
by: B Squared | last post by:
I'm trying to pass a filename (which is a jpeg image) to a php function / file so that it will display. I know that its simple to get PHP to display an image hardcoding in the filename. For...
5
by: u0107 | last post by:
Hello all, I have an ASP generated form to maintain a back end Access Database. Some tables have Memo Type fields. On account of the limitations of the length of the URL String, I am unable...
3
by: Bill Nguyen | last post by:
I would like to invoke the IE browser and pass values (lat and long) to function GtMap() the html file below from a VB.NET app. help, please! Thanks Bill ------------------------
5
by: jmartmem | last post by:
Greetings, I have built an Update Record Form in an ASP page. This form contains a number of fields, such as text boxes and menus, to name a few. Upon clicking the 'submit' button, I want the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.