Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

How to submit form with return

 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric

That worked great, thanks.

And that background colour change is the nuts Brilliant
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic