event trickery

J

J. Baute

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

Thomas 'PointedEars' Lahn

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top