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>I have tried to format it so it's easily readable, but can't be sure of
<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> </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>
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.