GeeCON Prague 2014*
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: 61299
    
  66

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: 61299
    
  66

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: 61299
    
  66

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.
 
GeeCON Prague 2014
 
subject: Enter key form submission