Connecting Tech Pros Worldwide Help | Site Map

event trickery

  #1  
Old July 23rd, 2005, 08:52 PM
J. Baute
Guest
 
Posts: n/a
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 ---

  #2  
Old July 23rd, 2005, 09:01 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo box API trickery Frank Rizzo answers 5 January 24th, 2007 06:45 AM
dismiss a listbox when mouseclick outside boundaries tbrown answers 4 December 26th, 2006 10:15 PM
programmatic firing of keydown event runner7 answers 9 September 11th, 2006 01:35 AM
Calling a funciton implicitly ? iceColdFire answers 9 July 23rd, 2005 05:35 AM