Can I use onkeydown with invoke?

12 views
Skip to first unread message

Nik

unread,
Sep 29, 2008, 5:41:46 PM9/29/08
to Prototype & script.aculo.us
Hello all,

I am wishing to do something like this:

$$('input.info').invoke('onkeydown', function(){...})

is that possible?

Basically, I want to limit all the input field with 'info' class to
allow only alphabets, number , backspace and space with a custom
function.

Thank You!

Hector Virgen

unread,
Sep 30, 2008, 2:30:58 AM9/30/08
to prototype-s...@googlegroups.com
You want to invoke the 'observe' method:

$$('input.info').invoke('observe', 'onkeydown', function(){...})

-Hector

Rick DeNatale

unread,
Sep 30, 2008, 6:32:06 AM9/30/08
to prototype-s...@googlegroups.com

You might want to have a look at lowpro as an adjunct to prototype

http://www.danwebb.net/2006/9/3/low-pro-unobtrusive-scripting-for-prototype
--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

kangax

unread,
Oct 1, 2008, 12:44:34 PM10/1/08
to Prototype & script.aculo.us
Maybe something like this should do it:

$$('input.info').invoke('observe', 'keydown', function(e) {
if (!(/^(\w|\s)+$/).test(String.fromCharCode(e.keyCode))) {
e.stop();
}
});

--
kangax

Edward Grant

unread,
Oct 10, 2008, 12:44:51 PM10/10/08
to prototype-s...@googlegroups.com
> Basically, I want to limit all the input field with 'info' class to
> allow only alphabets, number , backspace and space with a custom
> function.

I have had good luck using http://www.livevalidation.com It might be
more than you want but is great for making validations readable for
when you com back to the code later.


--
Edward Grant
themas...@gmail.com

Reply all
Reply to author
Forward
0 new messages