wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to submit form with return" Watch "How to submit form with return" New topic
Author

How to submit form with return

Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
Hi

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?

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

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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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.

Eric
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: http://aspose.com/file-tools
 
subject: How to submit form with return
 
Similar Threads
Submit form and close window
Encrypting using Javascript
Page reloading problem
Submit button problem
how can i hide the login in the url.