Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

javascript help

Options
  • 20-01-2006 10:56am
    #1
    Registered Users Posts: 7,517 ✭✭✭


    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 Posts: 7,517 ✭✭✭matrim


    *bump* Anyone?


  • Moderators, Category Moderators, Motoring & Transport Moderators Posts: 21,238 CMod ✭✭✭✭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 Posts: 7,517 ✭✭✭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