Connecting Tech Pros Worldwide Help | Site Map

event trickery

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 07:52 PM
J. Baute
Guest
 
Posts: n/a
Default 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=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, 08:01 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.