Results 1 to 6 of 6

Thread: A monkey could answer this [but hasn't yet]...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    A monkey could answer this [but hasn't yet]...

    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:



    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="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.
    Last edited by V(ery) Basic; Feb 14th, 2003 at 07:04 PM.
    Courgettes.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: A monkey could answer this...

    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...

    Code:
    <a href="java script:writeCourses();">Courses</a>
    Are you calling a java function or a javascript function?
    Change it to:
    Code:
    <a href="javascript script:writeCourses();">Courses</a>
    -- Stop ignoring here... resume reading >

    Next, javascript expects something in return....
    Change it to:
    Code:
    <a href="javascript script:writeCourses(); return false;">Courses</a>
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    (I did TRY using the Javascript forum.)

    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.
    Courgettes.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    Code:
    <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.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    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.
    Courgettes.

  6. #6
    Fanatic Member seec77's Avatar
    Join Date
    Jan 2003
    Posts
    596
    hey man!!
    do something like this!
    Code:
    <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>
    Best Regards,
    seec77

    If you helped me, cosinder yourself thanked.

    Get each and every Garfield strip here!
    Here you can get all Calvin & Hobes strips!
    Damn UComics! It was probably unprofitable for them to allow us to just download Garfield and Calving & Hobes strips... so they made folder indexing unallowed on their server!!!

    I am 33% addicted to Counterstrike. What about you?
    I am 23% addicted to Star Wars. What about you?
    I am 0% addicted to Tupac. What about you?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width