Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

javascript help

  • 20-01-2006 10:56AM
    #1
    Registered Users, Registered Users 2 Posts: 7,516 ✭✭✭


    Hi,

    I need some help with a javascript problem I'm having.
    I'm creating a drop down menu. This works fine but when I try to update it to be generic ('ie not hardcode the elementId into the functions) I run into a problem.

    I have a timeout around one method and this prevents me from passing the element id to the functions
    eg
    onmouseover='setTimeout('noshow()' 5000)'
    
    -- works ok
    If I want to pass a variable throught noshow it causes an error because I cannot quote it
    onmouseover('setTimeout('noshow([COLOR="Olive"]'elementid'[/COLOR])' 5000)'
    

    I then tried to add this to another function as
    function myTimeout(id)
    {
        setTimeout('noshow(id)' 5000);
    }
    

    called from
    onmouseover = "myTimeout('elementid')"
    

    This causes a javascript error - id is not defined.

    For other functions similar function calls work
    eg
    onmouseover = "show('elementid')" works.

    Has anyone any ideas what might cause this?


Comments

  • Registered Users, Registered Users 2 Posts: 7,516 ✭✭✭matrim


    *bump* Anyone?


  • Registered Users, Registered Users 2 Posts: 21,278 ✭✭✭✭Eoin


    sorry, edited post because I just realised my idea wouldn't work at all :(

    edit #2:
    Have you tried this:
    document.getElementById(elementIDHere)
    

    Not too sure from your examples, where exactly you would use it, but could be worth a go.


  • Registered Users, Registered Users 2 Posts: 7,516 ✭✭✭matrim


    eoin_s wrote:
    edit #2:
    Have you tried this:
    document.getElementById(elementIDHere)
    

    Not too sure from your examples, where exactly you would use it, but could be worth a go.

    That's what I have. The no show method is something like this
    function noshow()
    {
       element = document.getElementById('elementid');
       //do stuff
    }
    

    I want it in such a way that I can pass the element id as a variable in the function.
    eg
    function noshow(id)
    {
       element = document.getElementById(id);
       //do stuff
    }
    


    Otherwise if I want more than 1 drop down list, I've to have more than one noshow function.


Advertisement