JSP + Struts form submission problem

C

Chris

Hello all,

I have a form on a page that has multiple submit buttons. All three
submit buttons reference the same Action class, but do different tasks
depending on which button was pressed.
The problem I'm having is that when a user is on a certain text field
and presses the enter button on their keyboard, the wrong Submit button
is being used to submit the form. There are four text fields that
should use Submit button A, and one field that should use submit button
B and one field for submit button C. Is there a way to specify which
submit button should be used on a per-text-field basis? If not, is
there a way to specify which submit button to use when the enter key is
pressed on a form-wide basis.

Thanks so much for your help,

--chris.
 
W

Wendy S

Chris said:
I have a form on a page that has multiple submit buttons. All three
submit buttons reference the same Action class, but do different tasks
depending on which button was pressed.
The problem I'm having is that when a user is on a certain text field
and presses the enter button on their keyboard, the wrong Submit button
is being used to submit the form.

Multiple submit buttons are outside of what HTML forms were originally meant
to do, though they are not technically invalid. IE seems to send the first
button it finds after the <form> tag. Other browsers may act differently.

What I did was put a hidden button (with an image matching the background,
or CSS'd to be hidden) at the very top of the form. It does nothing but
repaint the form. And so the user hits enter, and (as far as they can tell)
nothing happens. You could also display a message telling them to click one
of the buttons, if that's appropriate for your app.
 
V

vered

Hi,

Something else that you can do is catch the "Enter" event in javascript
and handle it.

<script language="javascript" for="document">
if(event.keyCode == 13) { // 'Enter' event
window.returnValue = false; // prevent the submit
}
</script>
This will really do nothing when the user clicks "Enter".

Vered.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top