|
-
Feb 14th, 2003, 01:37 PM
#1
Thread Starter
Fanatic Member
A monkey could answer this...
You dont have to read this bit:
I am very new to Javascript. It doesn't like me and I don't like it. For long-winded and definitely boring reasons I find I have to use it, and as I am certainly not a talented web designer I find myslef trying to do the most basic thing, and failing in every respect.
My problem:
If the user clicks on a hyperlink, all I want is for 3 little sub-options to appear beneath it. This is my approach:
Code:
<head>
<title>Home Page</title>
<script language="Javascript" version="1.0">
var showCourse=false;
function writeCourses() {
showCourse=true;
return 0;
}
function getCourse() {
return showCourse;
}
</script>
</head>
And in the main bit in the <body> section:
Code:
<a href="javascript:writeCourses();">Courses</a>
<script language="Javascript" version="1.0">
if (getCourse()==true) {
document.write("<br>    <img src='images/select.gif' width='13' height='8'><a href='EC3001.htm'>EC3001</a>");
document.write("<br>    <img src='images/select.gif' width='13' height='8'><a href='EC3002.htm'>EC3002</a>");
document.write("<br>    <img src='images/select.gif' width='13' height='8'><a href='EC3003.htm'>EC3003</a>");
};
</script>
As I understand it, though obviously I don't, showCourse is declared as a global variable. Then (or so I would have hoped) when the user clicked on 'Courses', writeCourses() would have been called, setting showCourse to true, and then when the execution point came to the next bit, getCourse() would have returned true and everything would be great. But OH NO. I get a brand new page with a '0' (presumably from the "return 0;" line in writeCourses). Now from what I have seen elsewhere this ought to work. Please help me, as you have probably gathered that this is a source of much frustration to me.
Thanks again,
me.
-
Feb 14th, 2003, 08:26 PM
#2
Here, you are calling a document.write after the page has loaded. That is why the entire page gets replaced. What you ought to do is something like this:
Create your links, and under each link, create a 3 row table with your options.
<div id="dumbass1"><table >.....</table></div>
In your styles section, set
Code:
#dumbass1 {
visibility: false;
}
Then for your link:
Code:
<a href="" onClick = "javascript:showlayer('dumbass1');">First Link</a>
<a href="" onClick="javascript:showlayer('dumbass2');">Second LInk</a>
And you will have javascript like this:
Code:
function showlayer(layername)
{
eval('document.all["'+layername+'"].style.visibility="visible"');
}
HTH.
-
Feb 15th, 2003, 06:32 AM
#3
Thread Starter
Fanatic Member
Thanks mendhak, would this work in most browsers?
(and/or is there a way to use document.write once the page has loaded?)
Last edited by V(ery) Basic; Feb 15th, 2003 at 06:37 AM.
Courgettes.
-
Feb 15th, 2003, 08:35 AM
#4
Originally posted by V(ery) Basic
Thanks mendhak, would this work in most browsers?
(and/or is there a way to use document.write once the page has loaded?)
Uhm... works in IE actually :embarassed:
No, you can't write using document.write once the page has loaded.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|