object.onmouseover

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Laser Lips

    object.onmouseover

    HI All,

    Is it possible to do the following?

    object = document.getele mentById('somet hing');

    object.onmouseo ver='alert("hi" );';

    ............... ....


    I know that object.onmouseo ver=function(){ alert("hi");} is OK but I
    want to do it the first way. Can it be done?

    Graham
  • Martin Honnen

    #2
    Re: object.onmouseo ver

    Laser Lips wrote:
    object.onmouseo ver='alert("hi" );';
    >
    ............... ...
    >
    >
    I know that object.onmouseo ver=function(){ alert("hi");} is OK but I
    want to do it the first way. Can it be done?
    Assigning a function makes sense, assigning a string as you do does not
    make sense. So it can be done but is not in any way useful. If you have
    a string then you need to create a function from it:
    object.onmouseo ver = new Function('alert ("hi");');


    --

    Martin Honnen

    Comment

    • Laser Lips

      #3
      Re: object.onmouseo ver

      Thats just what I needed thanks. :0)
      Graham

      Comment

      • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

        #4
        Re: object.onmouseo ver

        Laser Lips escribió:
        Is it possible to do the following?
        >
        object = document.getele mentById('somet hing');
        >
        object.onmouseo ver='alert("hi" );';
        [...]
        I know that object.onmouseo ver=function(){ alert("hi");} is OK but I
        want to do it the first way. Can it be done?
        Do you need to execute code from a string or is it just an aesthetics
        question?

        In the latter case, this is not HTML; you don't need to pack all your
        code in one line. So (in my humble opinion) this looks just fine:

        object.onmouseo ver = function(){
        alert("hi");
        };

        You can also assign a named function:

        function sayHi(){
        alert("hi");
        }

        object.onmouseo ver = sayHi;


        In the former case you'd have to do this:

        object.onmouseo ver = function(){
        eval('alert("hi ");');
        };

        Not a good idea unless there's powerful reason.


        --
        -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
        -- Mi sitio sobre programación web: http://bits.demogracia.com
        -- Mi web de humor al baño María: http://www.demogracia.com
        --

        Comment

        Working...