Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Struts and the fly likes Pressing enter key submits page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Pressing enter key submits page" Watch "Pressing enter key submits page" New topic
Author

Pressing enter key submits page

paresh doshi
Ranch Hand

Joined: Nov 20, 2006
Posts: 81
I have a html:text box in my page. But when i press enter key in text box it submits page. I dont want the page to get submitted.

I have also used html:file in the same form.

Please let me know what could be the problem.


Thanks.<br />Paresh Doshi<br />SCJP 1.4
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

There's no problem -- that's the way forms work in HTML. If there is a submit button on the form, a return in any field will cause the button to trigger.

If that's not what you want, you can either replace the submit button with a non-submit button and use it to submit the form under JavaScript control, or you can establish an event handler on the form that captures the key event and blocks submission


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
jQuery in Action, 2nd edition
 
subject: Pressing enter key submits page
 
Similar Threads
the enter key forces a submit
How to capture enter key?
need help on passing string
How to deny the Enter key press action
onkeyup function