V(ery) Basic
Feb 14th, 2003, 04:22 PM
You can read this bit if you want:
Sorry, I know there is a Javascript forum for a question like this, but I'm sure you don't need to be specialised to help, and a quick answer would be great since the sooner I get this finished the better...
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:
<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:
<a href="java script: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.
Sorry, I know there is a Javascript forum for a question like this, but I'm sure you don't need to be specialised to help, and a quick answer would be great since the sooner I get this finished the better...
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:
<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:
<a href="java script: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.