cancel
Showing results for 
Search instead for 
Did you mean: 

Form submission on enter key

Former Member
0 Kudos

This should be simple for somebody.

How do you setup a jsp form and let the enter key perform the same action anywhere on the form as if a submit button was pressed.

// i.e If (keypressed = enter) call server event

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member194198
Active Participant
0 Kudos

I'm afraid I've not got a code sample with me but I've done this before using Javascript Events. You can have a piece of code that runs when the user presses any key ( onkeydown in the body tag etc)

It is possible to grab the event and get the keypress ('13' for enter). Google for javascript event handling and you should find out more.

As i remember, you have to set the event to false after you have hijacked it otherwise it will go and do the event anyway.

R

Former Member
0 Kudos

I've got a javascript which catches the keypressed event and filters for the enter key.

What I still need is

1. how to set the keypressed event to work for the form instead of just one input field.

2. how to invoke the server side event.

If I set up an htmlb button I specify the onClick event and it invokes the server event. How can I invoke the same event after cathing the enter key?

Former Member
0 Kudos

John,

If you are using HTMLB, there is a method in the Form class called setDefaultButton() which does this for you. You can call it when you define your submit button.

Here's one I did earlier:

<hbj:button id="Send_Button"

text="Submit" tooltip="Send feedback"

onClick="onSendButtonClicked" width="100"

design="EMPHASIZED">

<% myFormId.setDefaultButton(Send_Button); %>

</hbj:button>

HTH,

Rashad

Former Member
0 Kudos

Thanks Rashad.

Works exactly as hoped.