Connecting Tech Pros Worldwide Forums | Help | Site Map

event trickery

J. Baute
Guest
 
Posts: n/a
#1: Jul 23 '05
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=javascript>
<!--

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

function doSomething(){
alert("something");
}

//-->
</SCRIPT>

</HEAD>
<BODY>

<input type="button" value="test" onSomething="doSomething();"
onclick="test(this);">

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


Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#2: Jul 23 '05

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
Closed Thread