Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to submit form with return

 
Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric

That worked great, thanks.

And that background colour change is the nuts Brilliant
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic