473,405 Members | 2,262 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,405 software developers and data experts.

show_id is undefined

Daz
Hi everyone.

Firstly, I am aware of the multiple posts to do with this topic within
this group already. I have read most of the ones I could find and
couldn't not get a solid solution.

I am fairly new to javascript, so I have created a small project to see
what I can do. The project consists of 3 iframes. One iframe (top
left), displays a list of 10 DVDs, the iframe to the right of it,
displays my comments on that particular movie, and the big iframe
underneath it all, serves as a browser which will connect you to the
relevent page on the imdb.com website where you can read all about the
DVD. This project serves no purpose, it is simply for me to learn,
(just in case some of you are wondering what use this program might
be).

At the moment, the code is incomplete, I have managed to get a list of
URLs to display in the window I want, but the moment I click on one, it
does nothing apart from giving me a big error telling me the function
does not exist. I have spend a while changing things, and making new
functions to see if they work instead, and changig the formats of the
hrefs within the <atags, and I have even tried using onclick(). Non
of this seems to work, as I still get the same error.

Below is my entire script. I know it's big, but as I can't be sure
where the error lies, I may as well show you the whole thing to see if
you can shed any light on the subject.

CODE:
<html>
<head>
<title>DVDs<title>
</head>

<body>
<table width="100%"
border="0"
cellpadding="0">
<tr>
<td width="25%">
<iframe
id="LINKS"
name="LINKS"
src="blank.html"
width="100%"
height="100%">
</iframe>
</td>
<td width="75%">
<iframe
id="COMMENTS"
name="COMMENTS"
src="blank.html"
width="100%"
height="100%">
</iframe>
</td>
</tr>
</table>
<iframe
id="BROWSER"
name="BROWSER"
src="blank.html"
width="100%"
height="75%"
frameborder="1">
</iframe>

<script type="text/javascript">

// Handles to the iFrames.
var f_browser; // Main iFrame where the imdb page will be displayed.
var f_comments; // iFrame where my comments will be displayed.
var f_urls; // iFrame where the urls for each DVD review will be displayed.

// This function creates a handle to each Frame, and returns more than
// '0' if there was an error.
function make_frame_handles() {
var errors=0;

// Attempt to make handle for urls Window.
f_urls = window.frames.LINKS;
if (!f_urls) errors++;
//else f_urls.document.close();

// Attempt to make handle for comments Window.
f_comments = window.frames.COMMENTS;
if (!f_comments) errors++;

// Attempt to make handle for browser Window.
f_browser = window.frames.BROWSER;
if (!f_browser) errors++;

return errors;
}

//================================================== ==========

// This function initializes the page
function initialise_page() {
var errors = make_frame_handles();
if (errors>0) {
var error_msg =
+ "<p>&nbsp;</p><center><span style='color:red;font-size:14pt'>"
+ "ERROR!<br /><br /></center>"
+ "An error has occured!<br />"
+ "Please close this page and reopen it again<br /><br />"
+ "Note: A page refresh will <u><b>NOT</b></ufix this error!</span>";
document.write(error_msg);
}
else {
display_urls();
}
}
// Array to store the information about each DVD.
var dvd_info = new Array(); // 0=Film Name, 1=url, 3=comments (if any).
dvd_info[0] = Array('40 Year Old Virgin', '', '');
dvd_info[1] = Array('Antz', '', '');
dvd_info[2] = Array('Cellular', '', '');
dvd_info[3] = Array('Failure to Launch', '', '');
dvd_info[4] = Array('Lucky Number Slevin', '', '');
dvd_info[5] = Array('Man on Fire', '', '');
dvd_info[6] = Array('Monster in Law', '', '');
dvd_info[7] = Array('Spanglish', '', '');
dvd_info[8] = Array('Taxi', '', '');
dvd_info[9] = Array('V For Vendetta', '', '');

//================================================== ==========

// Changes the page to show the specified information.
function show_id(id) {
display_urls(id);
var url_to_load;
var comment_to_display;
}

//================================================== ===========

function display_urls(url_id) {
for (var i=0; i < dvd_info.length; i++) {
if (i == url_id)
f_urls.document.write('<span style="color:blue;background:yellow;'
+ 'border-style:solid;border-width:1px;margin-top:100px;'
+ 'margin-bottom:100px"><b>' + dvd_info[i][0] + '</b></span><br />');
else
f_urls.document.write('<a href="javascript: show_id(\'' + i + '\');\">' + dvd_info[i][0] +
'</a><br />');
}
}

//================================================== ==========

initialise_page ()

</script>
</body>
</html>
I have tried to format it so it's easily readable, but can't be sure of
the results. Also, there may be a few errors in the script which I'd
appreciate having pointed out to me.

Many thanks in advance.

Nov 4 '06 #1
1 1891
ASM
Daz a écrit :
Hi everyone.

Firstly, I am aware of the multiple posts to do with this topic within
this group already. I have read most of the ones I could find and
couldn't not get a solid solution.
To reach a frame or iFrame, best way is to give it a *name*

<html>
<iframe name="left" blah ></iframe>
<iframe name="right" blah ></iframe>
<iframe name="bottom" blah ></iframe>
</html>

Then about a link in file displayed in 'left'
to call comment file in 'right', and relevent file in 'bottom'

<a href="#" title="fantastic"
onclick="parent.right.location='mov_1_comment.htm' ;
parent.bottom.location='http://imdb.com/?id=mov_1';
return false;
">film 1</a>

On my idea this :
> // Attempt to make handle for urls Window.
f_urls = window.frames.LINKS;
will not work if you call 'f_urls' directly from file displayed in one
of your iframes ... (what you do in your document.write() )
Why ?
Because 'f_urls' is a variable (shortcut) in parent window of the iframes.

So i.g. in 'left' :

<a href="#" onclick="
parent.f_browser.location='http://imdb.com/?id=mov_1';
return false;
">film 1</a>
So, in your example :

function show_id(id) {
display_urls(parent.id);
var url_to_load;
var comment_to_display;
}

could work ... (not tested)

I would do :

function menu(index) {
var t1 = '<html style="background:yellow;color:blue">';
var t2 = '<span style="border:1px solid red;'+
padding:8px;margin:20px;font-weight:bold">';
for(var i=0; i < dvd_info.length; i++)
if(i==index)
t1 += t2+dvd_info[i][0]+<\/span><br />'
else
t1 += '<a href="javascript:show('+i+')">'+
dvd_info[i][0]+<\/a><br />';
t1 += '<\/html>';
parent.LINKS.document.open();
parent.LINKS.document.write(t1);
parent.LINKS.document.close();
}
onload = menu;

function show(index) {
if(dvd_info[index][2] != null) {
parent.COMMENTS.document.open();
parent.COMMENTS.document.write(comment(index));
parent.COMMENTS.document.close();
}
if(dvd_info[index][1] != null) {
parent.BROWSER.location=dvd_info[index][1];
}
}

function comment(index) {
var t = '<html style="background:yellow;color:blue">';
t += '<h2>Comment :<\/h2>';
t += '<div style="border:1px solid blue;'+
padding:8px;margin:5px 20px;">';
t += dvd_info[index][2]+<\/div><\/html>';
return t;
}
>function display_urls(url_id) {
f_urls.document.open();
> for (var i=0; i < dvd_info.length; i++) {
if (i == url_id)
f_urls.document.write('<span style="color:blue;background:yellow;'
+ 'border-style:solid;border-width:1px;margin-top:100px;'
+ 'margin-bottom:100px"><b>'+dvd_info[i][0]+'<\/b><\/span><br />');
> else
f_urls.document.write('<a href="javascript: show_id(\'' + i + '\');\">' +
dvd_info[i][0] +'<\/a><br />');
> }
f_urls.document.close();
>}

//================================================== ==========

initialise_page ()
onload = initialise_page;
></script>
</body>
</html>
--
ASM
Nov 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on...
1
by: Stu | last post by:
I am trying to build the xerces shared library with 2.3.0 version of their source code on an AIX 5.1 32 bit machine with the following version of the g++ compiler /usr/local/bin/g++ -v Reading...
4
by: Mike | last post by:
I am having a problem when a field is spaces being undefined. I wasn't sure if the problem was Excel or Javascript, so I thought I would post here first. The users are able to select from a drop...
1
by: Codemutant | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** I just cannot find what is undefined in this code.
1
by: Foolster41 | last post by:
I'm rather new to C++ programing. I'm using the dev-C++ program on a windows XP OS. I'm trying to compile the code for a multi user dungeon (MUD) called circle-mud. When I compile I get the...
4
by: Chris Beall | last post by:
If you want your code to be bulletproof, do you have to explicitly check for the existence of any possibly-undefined variable? Example: window.outerHeight is defined by some browsers, but not...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
3
by: Michael Sgier | last post by:
Hi i get thousands of messages like below. How shall i resolve that? Thanks Mcihael Release/src/Utility/RawImage.o: In function `CMaskImage::CMaskImage(int, int, char const*)':...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.