SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Only first command works

    I've got the following code to execute different functions when various page elements are clicked:

    Code:
       window.onload = function(){
     
       	var helpLinks = document.getElementsByTagName('a');
       	for(var i=0; i<helpLinks.length; i++){
        	if(helpLinks.className == 'help-popup'){
        			helpLinks.onclick = helpPopup;
       			return false;
       		}
       	}
       
       	var confirmLinks = document.getElementsByTagName('a');
       	for(var i=0; i<confirmLinks.length; i++){
       		if(confirmLinks[i].className == 'confirm'){
       			confirmLinks[i].onclick = confirmHandle;
       		}
       	}
       
       	var confirmLinks2 = document.getElementsByTagName('input');
       	for(var i=0; i<confirmLinks2.length; i++){
       		if(confirmLinks2[i].className == 'confirm'){
       			confirmLinks2[i].onclick = confirmHandle;
       		}
       	}
       
       	var menu = document.getElementById('quickhelp-active');
       	menu.onmouseover = showMenu;
       	menu.onmouseout = hideMenu;
       
       }
    The problem is only the first part (in this case the helpLinks part) is working, whereas the others are ignored. I can swap them around as well and it's always the first part which is noticed by the browser.

    I'm a bit of a JavaScript newbie I'm afraid, but any help would be much appreciated

    Sam
    Sam Hastings

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if(helpLinks.className == 'help-popup'){
    helpLinks.onclick = helpPopup;


    This is wrong, it should be
    if(helpLinks[i].className == 'help-popup'){
    helpLinks[i].onclick = helpPopup;


    And this line:
    return false;

    will exit the function once it is reached, do you really want that there?

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seems like vBulletin didn't want me to paste the proper code in here, the array keys [i] were in the code, they were just removed for some reason.

    Anyway, removing the return false; line seemed to do the trick. I put that line in the helpPopup function instead.

    Everything seems fine... for now.

    Thanks for your help

    Sam
    Sam Hastings

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    welcome =)


Bookmarks

Posting Permissions

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