Javascript in html attribute

Discussion in 'JavaScript' started by kenoli, Sep 9, 2007.

  1. #1
    I am trying to understand some existing script and came across the following application of javascript in html attributes in an <a> tag. It was generated by php so it might not be the most orthodox javascript.

    onmouseover="window.status='View this entry'; show(event, 'eventinfo-224-5'); return true;" onmouseout="window.status=''; hide('eventinfo-224-5'); return true;"

    I assume what is going on here is the same as the following javascript (show and hide being pre-defined functions):

    window.status='View this entry';
    show(event, 'eventinfo-224-5');
    return true;

    and:

    onmouseout=window.status='';
    hide('eventinfo-224-5');
    return true;

    Any comments on this way of including javascript scripts? Can one include scripts in any attribute in this manner? Is there no need for <script> tags? Other comments?

    Thanks,

    --Kenoli
     
    kenoli, Sep 9, 2007 IP
  2. Synchronium

    Synchronium Active Member

    Messages:
    463
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Technically you could include all your code like that, but more often than not you use the onclick etc tributes for the functions as event handlers. They'll contain onclick="javascript:function()" and function will have already been defined in an external script file or something.

    Check out the source of my site: http://www.coffeesh0p.com for some more examples. :)
     
    Synchronium, Sep 10, 2007 IP