onclick runs straight away....

Discussion in 'Javascript' started by windandwaves, Feb 18, 2006.

  1. windandwaves

    windandwaves Guest

    Hi Gurus

    I have the following JS:

    var lin1 = document.getElementById('amui');
    lin1.onclick = OWi(getimagename(mouseOvers[i1].src));

    the onclick command executes straight away (before I click on the amui
    element). What can I do about this? I dont understand it at all...

    TIA

    Nicolaas
     
    windandwaves, Feb 18, 2006
    #1
    1. Advertising

  2. windandwaves

    Guest

    Try putting the JS in <head></head> portion.
     
    , Feb 19, 2006
    #2
    1. Advertising

  3. windandwaves

    windandwaves Guest

    Ian Collins wrote:
    > windandwaves wrote:
    >> Hi Gurus
    >>
    >> I have the following JS:
    >>
    >> var lin1 = document.getElementById('amui');
    >> lin1.onclick = OWi(getimagename(mouseOvers[i1].src));
    >>
    >> the onclick command executes straight away (before I click on the
    >> amui element). What can I do about this? I dont understand it at
    >> all...

    > You aren't assigning a function to onclick, you are calling the
    > function and assigning the result!
    >
    > Assuming OWi the the function you wish to call,
    >
    > lin1.onclick = function() { OWi(getimagename(mouseOvers[i1].src)); };


    Great - thank you Ian. It starts to make sense.
     
    windandwaves, Feb 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Beza
    Replies:
    2
    Views:
    418
    Kevin Spencer
    Jun 27, 2003
  2. Kathy Burke
    Replies:
    2
    Views:
    3,498
    Kathy Burke
    Oct 16, 2003
  3. Jordan
    Replies:
    2
    Views:
    2,539
    Jordan
    Feb 10, 2004
  4. Nx

    run runs away

    Nx, Nov 29, 2005, in forum: Python
    Replies:
    3
    Views:
    289
  5. Daves
    Replies:
    4
    Views:
    211
    Keith Patrick
    Jan 16, 2006
Loading...

Share This Page