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
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts

    function doesn't always return a value ... but I can't find a safe value to return

    I've got an anonymous function attached to a link, which might be activated via onclick or onmouseover - in both cases the handler opens a submenu, but if it's onclick it should return false so the link isn't followed.

    Essentially:
    Code:
    linkObject[eventHandler] = function(e)
    {
    	this.openMenu(e.target);
    	
    	if(eventHandler == 'onclick')
    	{
    		return false;
    	}
    
    }
    Fine, but that generates a strict warning - "anonymous function does not always return a value".

    Trouble is ... I can't return anything else except false, because then the link HREF doesn't show up in the status bar in Internet Explorer when you hover over it!

    And I can't universally return false either, because events from links in nested menus won't work anymore - they'll bubble up and return false - so you won't be able to click them.

    So what can I do? I just wanna get rid of that strict warning, so I guess I either need another way of phrasing that anonymous function, or I need a solution to why any other return value but false makes the links not show up in the status bar in IE.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    The default return from any function that has no explicit return statement is undefined. So, including a clean return; at the end of the function should do it.

    As for bubbling, have you considered returning false on the top level in the menu, or returning false but explicitly triggering the event on the parent node?

    [edit:]the first of which does not work, the second of which is not needed since returning false does not cancel the cascade.
    Last edited by liorean; 03-16-2004 at 03:16 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Follow-up for reference - with liorean's help we got this issue nailed down.

    IE was not showing the mouseover status text with any return value but false, but if it's always returning false then the links in nested menus don't work.

    Then to add a spanner in the works, Opera 7 and MSN have the opposite problem from IE - the status text only shows if the mouseover returns true.

    So the solution was to find the event-type - click or mouseover - and then return true or false depending on the event and browser. Like this:
    Code:
    linkObject[eventHandler] = function(e)
    {
    	this.openMenu(e.target);
    	
    	if(eventHandler == "onclick")
    	{
    		return false;
    	}
    	
    	return (e.type == "click" || isOP7 || isMSN);
    }
    Last edited by brothercake; 03-15-2004 at 09:56 AM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

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