I have onmouseover executing a command but want it executed when the page loads

Discussion in 'JavaScript' started by Maxedout, May 8, 2011.

  1. #1
    The code below works correctly if I mouse over, but I need to make this command to be actioned by default when the page is loaded.

    This text returns the result I need ----> getclinic(0,'ON');" class="clinic-link

    Can anyone help?

    ===== snippet code starts ====
    <div id="main-clinic-locator">

    <a href="#" onmouseover="javascript:getclinic(0,'ON');" class="clinic-link">Mouseover Here<br />for Map &amp; Directions<br /> to the Winchester Clinic</a>

    </div>
    ===== snippet code ends ====

    Thanks Maxi :eek:
     
    Maxedout, May 8, 2011 IP
  2. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Hi, try this:

    <script>
    window.onload=function(){
    getclinic(0,'ON');
    //here can be also another code which you want to run after loading page
    }
    </script>
     
    Jan Novak, May 8, 2011 IP
  3. Maxedout

    Maxedout Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi Jan

    Thanks for the pointer... unfortunately it did not fire up the default Google map unless I inserted the following text some where .... class="clinic-link" .... after the getclinic(0,'ON'); line. However, no matter how I have inserted that text, whilst it fires up the default Google map it does not behave the same as the onmouseover action where it takes the Clinic address from the ..... <a href="#" onmouseover="javascript:getclinic(0,'ON');" class="clinic-link"> .... code and fires up the map with the correct coordinates.

    It appears I am not inserting that second important piece in correctly.... class="clinic-link" .... see below one example, which throws up an error, but does at least fires up the default google map.


    <div id="main-clinic-locator">
    <script>
    window.onload=function(){
    getclinic(0,'ON');
    '<div class="clinic-link"></div>';
    }
    </script>
    </div>

    Any further suggestions.
    Thanks Maxi
     
    Maxedout, May 9, 2011 IP
  4. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #4
    It seems like the functionallity works correctly after asynchronous javascript is done. Could you please post full URL where problem appears?
     
    Jan Novak, May 9, 2011 IP
  5. Maxedout

    Maxedout Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi Jan, sent link via PM. Thx
     
    Maxedout, May 9, 2011 IP
  6. Maxedout

    Maxedout Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi Jan, that 2nd fix does work. Many thanks
     
    Maxedout, May 9, 2011 IP