can you "inline" event handlers for objects in 1 script like in VBScript?

Discussion in 'Javascript' started by Fred, Jul 18, 2003.

  1. Fred

    Fred Guest

    This seems awkward, isn't there a better way to place event handlers
    in the rest of the code with the logic for everything else like you
    can with VBScript?

    <script language="javascript"
    if (myvar == true " {
    do something
    }
    lots more code here...

    </script>

    <script for="myActiveX" event="Onclick()" language="javascript">
    code for this event
    </script>

    <script for="myTreeView" event="OnConnect()" language="javascript">
    code for this event
    </script>
    ....

    In other words, can I put it all between one <script></script> tag?

    Thanks,

    Fred
     
    Fred, Jul 18, 2003
    #1
    1. Advertising

  2. (Fred) writes:

    > This seems awkward, isn't there a better way to place event handlers
    > in the rest of the code with the logic for everything else like you
    > can with VBScript?


    I don't know what you can with VBScritp. Can you explain what you want
    to achieve?

    > <script for="myActiveX" event="Onclick()" language="javascript">


    This construction only works in IE.

    > In other words, can I put it all between one <script></script> tag?


    Sure

    <script type="text/javascript">
    function myHandler1(event) {...}
    function myHandler2(event) {...}
    ...
    document.getElementById("myActiveX").onclick = myHandler1;
    document.getElementById("myActiveX").onconnect = myHandler2;
    /* don't know the onconnect evemt, must be IE specific too */
    </script>

    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Jul 18, 2003
    #2
    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. Richard Dixson
    Replies:
    1
    Views:
    542
    Joe Fallon
    May 18, 2004
  2. Paco
    Replies:
    0
    Views:
    312
  3. TS
    Replies:
    12
    Views:
    1,364
  4. Gert Unterhofer
    Replies:
    0
    Views:
    156
    Gert Unterhofer
    Jul 17, 2006
  5. Adam Short
    Replies:
    2
    Views:
    468
    Bob Barrows [MVP]
    Apr 14, 2005
Loading...

Share This Page