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 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    41
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Two Second onClick Problem

    Hello Everyone! I have one link that I need to do two onclick events at once. At first I just tried writing them both but that obviously didn't work b/c I'm here! This would result in the first onclick event tacking place and not the second. So my question is could someone tell me how to write this code in javascript, so both events will take plack onclick, and then how I should reference that script within my link? Thank you for taking a look

    Code:
    <a href = "javascript:void(0)" 
    
    onclick = "document.getElementById('light<?php echo $count;?>').style.display='none';document.getElementById('fade<?php echo $count;?>').style.display='none'"
                
    onclick = "document.getElementById('light<?php echo $count + 1;?>').style.display='block';document.getElementById('fade<?php echo $count + 1;?>').style.display='block'"> Previous 
    
    </a>

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    get rid of the " onclick=" in the middle of the onclick so that all the JavaScrip t is inside of the first one. The last onclick overwrites any previously attached.

    Alternatively update your code into the 21st century and use event listeners in an external JavaScript file instead of event handlers in the HTML. With event listeners you can attach multiple listeners to the same event on the same element whereas with event handlers there can be only one.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    ccarrin2 (03-12-2012)

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    41
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Got it working! Thank You!

  • #4
    New Coder
    Join Date
    Jan 2012
    Posts
    41
    Thanks
    6
    Thanked 0 Times in 0 Posts
    I don't want to be that guy who starts a new thread for a similair problem so I thought I'd ask for additional help here. I currently have two onclick events for when a user clicks a Previous arrow to go to the previous lightbox but is it also possible to add another event that would carry out the same function if they clicked the left arrow key on their keyboard? In other words let users scan through images similair to facebook with just their arrow keys. Thank you for reading.

    Code:
    <a href = "javascript:void(0)" onclick =
                   "document.getElementById('show<?php echo $count;?>').style.display='none';
                    document.getElementById('hide<?php echo $count;?>').style.display='none'
                    
                    document.getElementById('show<?php echo $count - 1;?>').style.display='block'; 
                    document.getElementById('hide<?php echo $count - 1;?>').style.display='block'"> 
    
    <?php echo "<<<"; ?> 
    
    </a>

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    41
    Thanks
    6
    Thanked 0 Times in 0 Posts
    If it helps I found this article http://www.javascriptkit.com/jsref/e...ardmouse.shtml which seems to be what I am looking for but I am not sure how to use it in my code! thanks again


  •  

    Posting Permissions

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