• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enter key

 
Mary Cole
Ranch Hand
Posts: 362
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Am using Struts framework and i have 3 buttons on the page. My action class extends DispatchAction.
How do I make the form submit for a particular action on pressing the enter key.

Pls this is urgent

Thx in advance
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not really a Struts-specific issue.

A browser will usually submit the form using the first button it rendered to the page when the Enter key is pressed. To get around this, you will need a javascript solution OR design your page so that the button you want pressed upon an Enter keypress is the first button in the text of your html.
 
alan do
Ranch Hand
Posts: 354
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to use javascript to submit your form. the script should:
1. detects keypressed (check for event.key == 13; look online for samples
(2. your DispatchedAction parameter in an unset hidden form field - inside the form, not done by the javascript)
3. set the parameter value to the name of the DispatchedAction you want to call
4. form.submit()

to accomodate the clicking of the the other 2 buttons, you only have to have another javascript submit method doing step 2 and 3 above. of course the form fields must be of type 'button' and you call the submit method 'onclick'.

-/a
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic