[Javascript] looking for HACK for events

Hassan Schroeder hassan at webtuitive.com
Wed Oct 8 15:41:48 CDT 2003


Walter Torres wrote:

> And since they are independent, don't know each other exists 

>    function doActions(){
>        doStatus();
>        doPassword();
>    }

> I thought of the doActions() concept. I just don't know how to tell it to
> add (pick your method) to its command list.

Ah, I got it now. You want new functions to "register" to be
called by a function triggered by an event. Here's an example
of how you could "register" a function manually; making each
set do it onload automatically shouldn't be difficult :-)

<script type="text/javascript">
function doStatus()
{
	alert('status');
}

function doPassword()
{
	alert('password');
}

function doDishes()
{
	alert('dishes');
}

function register(func)
{
	keyPressFunctions[keyPressFunctions.length] = func + "()";
}

var keyPressFunctions = new Array("doStatus()", "doPassword()");
function doActions()
{
	for ( var i = 0; i < keyPressFunctions.length; i++ )
	{
		eval(keyPressFunctions[i]);
	}
}

window.onkeypress = doActions;
</script>

<form>
<input type="button" value="add me" onclick="register('doDishes');"/>
</form>

/* only tested in Moz ... */

HTH!
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.






More information about the Javascript mailing list