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