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 to the CF scene
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onclick doesn't seem to work without an alert()

    My javascript function below is written to control the visibility of the "next" and "previous" buttons used to page through an image gallery (eg. showing images 1-10 of 50. press next to show 11-20 etc.)

    When I remove the alert("!"); it will no longer hide and show the next/previous buttons as it does with the alert("!"). It does however seems to work OK when I do include the alert("!"), which is a pain as obviously it pops up every time you move to the next page.

    javascript Code:

    Code:
    <script type="text/javascript">
    
    function hideShow(x, hv, imgno) {
        alert("!");
        if (x == "next" && hv < 8) {
            document.getElementById(x).style.visibility="hidden";
        }
        if (x == "previous" && imgno <= 9) {
            document.getElementById(x).style.visibility="hidden";
        }
    }
    </script>



    Below is the HTML that calls the javascript:

    Code:

    Code:
    <div id="previous" onclick="hideShow('previous',hv,imgno)">
    <a href="#" class="nav_r" onclick="document.location.href='MY_URL'; return false;">Previous</a>
    </div>
    <div id="next" onclick="hideShow('next',hv,imgno)">
    <a href="#" class="nav_r" onclick="document.location.href='MY_URL'; return false;">Next</a>
    </div>


    Any help will be greatly appreciated

  • #2
    Regular Coder
    Join Date
    Oct 2006
    Posts
    107
    Thanks
    3
    Thanked 5 Times in 5 Posts
    <a href="#" class="nav_r" onclick="document.location.href='MY_URL'; return false;">Previous</a>

    You are sending everyone off the page so, why bother?

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,080
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    This is a bug in IE. You need to create a slight delay before the function runs using setTimeout() (which is effectively what the alert is doing).

    But as rubenbuhr says, what is the point as the user is leaving trhe page?


  •  

    Posting Permissions

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