PDA

Click to See Complete Forum and Search --> : A monkey could answer this [but hasn't yet]...


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.

techgnome
Feb 14th, 2003, 04:42 PM
Originally posted by V(ery) Basic
You can read this bit if you want:
Sorry, I know there is a Javascript forum for a question like this,

Then why did you post it in the VB section?!
Originally posted by V(ery) Basic
but I'm sure you don't need to be specialised to help,

But it's still going to require Javascript knowledge.... which a lot of VBers don't have....

Originally posted by V(ery) Basic
and a quick answer would be great since the sooner I get this finished the better...


Most people read through ALL of the forums....
I will point out what I think might be wrong.....

< -- Begin ignoring me here for a few lines...... I'm just now seeing that you had js w/ a space in between.....I am going to presume that it's for the ben of the post and not actual code...


<a href="java script:writeCourses();">Courses</a>

Are you calling a java function or a javascript function?
Change it to:
<a href="javascript script:writeCourses();">Courses</a>


-- Stop ignoring here... resume reading >

Next, javascript expects something in return....
Change it to:
<a href="javascript script:writeCourses(); return false;">Courses</a>

V(ery) Basic
Feb 14th, 2003, 04:59 PM
Thanks for the help, techgnome. the 'java script' thing was due to the way I copied and pasted it all in.

Anyway, I tried your code but unfortunately I got another error saying 'return' didn't belong outside a function block. Then I realised you had written 'javascript script:' and tried that, but got a 'Page Cannot Be Displayed' when I clicked on 'Courses', which is strange.

In spite of my shameless wrong-forum posting, please keep helping.

silva
Feb 14th, 2003, 08:51 PM
<a href="javascript:writeCourses();">Courses</a>

<script language="Javascript" version="1.0">
function writeCourses() {
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>


Try that.

The other stuff seems to be doing nothing, as it would only write the courses information when the page is loaded and it would not work when the link is clicked. For that you would need a function, so try the above. :)

s.

V(ery) Basic
Feb 15th, 2003, 03:55 AM
Thanks so much for the help, but as I say Javascript has a problem with me. For some reason it writes the three lines to new document, which it then loads. I can't understand why it does this. Please keep helping,

Thanks again silva,

me.

seec77
Feb 15th, 2003, 08:06 AM
hey man!!
do something like this!

<script>
function openLinks(){
hidden_links.style.visibility="visible"
}
</script>
<a href="javascript:openLinks()">asdasd</a>
<div id=hidden_links style="visibility:hidden">links here</div>