Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2004
    Location
    London, England
    Posts
    95
    Thanks
    0
    Thanked 0 Times in 0 Posts

    newbie. Don't understand return false from a function

    My first ever question; pls let me know if it's formulated in a suitable style. This Script:

    <SCRIPT LANGUAGE="JavaScript">
    <!-- Hide code from older browsers
    function heading() {
    return false;
    }
    // End hiding-->
    </SCRIPT>

    Is referenced:

    <A HREF="./politics.htm" onClick="heading()">my politics</a>
    <A HREF="./politics.htm" onClick="heading(); return false">my politics 2</a>
    <A HREF="./politics.htm" onClick="return true">my politics 3</a>

    In case 1 I expected the link not to be taken, but it is.
    Case 2 link not taken, as expected
    Case 3 link taken, as expected.

    In what respect is my expectation wrong for case 1?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The calls are incorrect:

    Code:
    <A HREF="./politics.htm" onClick=" return heading()">my politics</a>
    <A HREF="./politics.htm" onClick="heading(); return false">my politics 2</a>
    <A HREF="./politics.htm" onClick="return true">my politics 3</a>
    You need to "return" the value from the function, just calling the function inline without the return verb causes the value returned by the function to be ignored.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    New Coder
    Join Date
    Jan 2004
    Location
    London, England
    Posts
    95
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Roy Sinclair
    You need to "return" the value from the function,
    Thank you, Roy. What a , sorry.


  •  

    Posting Permissions

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