views:

69

answers:

1

I've seen some other questions around this, but none for Prototype.

I have a form without a submit button (uses a styled link that calls some javascript).

What's the best way to detect a enter keypress in all the input fields and submit the form?

Thanks!

+1  A: 

This is an example of the kind of thing you could use:

$('input').observe('keypress', keypressHandler);

function keypressHandler (event){
    var key = event.which || event.keyCode;
    switch (key) {
        default:
        break;
        case Event.KEY_RETURN:
            $('yourform').submit();
        break;   
    }
}
seengee