show_id is undefined

D

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 <a> tags, 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></u> fix 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[0] + '</b></span><br />');
else
f_urls.document.write('<a href="javascript: show_id(\'' + i + '\');\">' + dvd_info[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.
 
A

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>




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[0]+<\/span><br />'
else
t1 += '<a href="javascript:show('+i+')">'+
dvd_info[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;
}


f_urls.document.open();


dvd_info[i][0] +' said:
f_urls.document.close();
}

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

initialise_page ()

onload = initialise_page;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top