event trickery

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J. Baute

    #1

    event trickery

    Hi,

    I'm trying to define/create a custom "event" for an input control (or
    whatever really).

    What I'm looking for is to define an event which contains some
    javascript code that I can later on call from other code. This could
    be used to create some sort of form field validation on submitting the
    form for instance.

    Currently I've found a way to make this work, but I'm wondering if
    there isn't a cleaner or better way to do this.

    --- start ---
    <HTML>
    <HEAD>

    <SCRIPT LANGUAGE=javasc ript>
    <!--

    function test(o) {
    alert("test");
    // create "event handler" in input control using the evil eval
    statement
    eval("o.onSomet hing = function anonymous(){" +
    o.getAttribute( "onSomethin g") + "};");
    o.onSomething() ; // call new event handler
    }

    function doSomething(){
    alert("somethin g");
    }

    //-->
    </SCRIPT>

    </HEAD>
    <BODY>

    <input type="button" value="test" onSomething="do Something();"
    onclick="test(t his);">

    </BODY>
    </HTML>
    --- end ---

  • Thomas 'PointedEars' Lahn

    #2
    Re: event trickery

    J. Baute wrote:
    [color=blue]
    > I'm trying to define/create a custom "event" for an input control
    > (or whatever really).[/color]

    Events are defined by the DOM, so unless you write a UA, and a DOM
    including an appropriate ECMAScript language binding of your own,
    forget it. The approach you presented is not even Valid HTML, let
    alone host objects do not have to provide a mechanism that actually
    adds properties.


    PointedEars

    Comment

    Working...