File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes How to submit form with return 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 "How to submit form with return" Watch "How to submit form with return" New topic

How to submit form with return

Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464

Can anyone please tell me how to set up a form so that return "hits" a button that is NOT of type submit.

The reason for this is that I run a JavaScript function instead of submitting the form straight away to validate the input. If I use a submit button the form gets submitted when you press return regardless of the JS function, if I use a button the return key does not hit the button.

My validate function is:

The two buttons I have tried are:

This submits the form on pressing return without going through the validate function (although the function is run as well).

This works as expected but is not hit when return is pressed.

NOTE - on Click entered with a space as the forum wouldnt allow the proper version.

Any ideas?

[ January 13, 2005: Message edited by: Nick Leaver ]

ph34r my 133t j4v4 h4><0r1ng sk177z
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
What you need to do is use the onsubmit event handler in the form tag.

You JavaScript code needs to return true or false

basic example:

Hope that helps you out.

Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
Hi Eric

That worked great, thanks.

And that background colour change is the nuts Brilliant
I agree. Here's the link:
subject: How to submit form with return
It's not a secret anymore!