File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Enter key form submission Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Enter key form submission" Watch "Enter key form submission" New topic
Author

Enter key form submission

Abhi Singh
Greenhorn

Joined: Feb 02, 2010
Posts: 13


I have one text field and one button('Find') on my JSP page. If I press 'Enter' key my form is getting submitted without validation.
I have no submit button on my page. Although I have handled that problem by checking Enter key code. But I wnat to know the
root cause and its probably its solution
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

Nothing to do with JSP. Moved to the HTML forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

How do you have the validation hooked up? Can't help you with the scant info you have provided.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You need to validate with onsubmit of the form, not onclick of a button.

Eric
Abhi Singh
Greenhorn

Joined: Feb 02, 2010
Posts: 13
Eric Pascarello wrote:You need to validate with onsubmit of the form, not onclick of a button.

Eric


there is no submit button on my page.
I have used find button and it onclick is handled in js
$(.findbuttonclass).click(function(){
validateFind();
});
Abhi Singh
Greenhorn

Joined: Feb 02, 2010
Posts: 13
Bear Bibeault wrote:How do you have the validation hooked up? Can't help you with the scant info you have provided.

there is no submit button on my page.
I have used find button and it onclick is handled in js
$(.findbuttonclass).click(function(){
validateFind();
});

function validate(){
if(document.getElementById("account")==""){
return false;
}
}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

As Eric has already pointed out, a click handler is the worst possible place to handle validation. Us a submit handler established on the form.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enter key form submission
 
Similar Threads
Submitting with "Enter" from textbox where there are several submit buttons on form
hitting the enter on the keyBoard should default to "YES" button on the html/jsp page
JavaScript
invoke js method
How to avoid submit on enter?