[thelist] Stopping Form Submission when Enter is hit

Richard Livsey R.Livsey at cache-22.co.uk
Wed Jul 18 09:57:02 CDT 2001


> On 18 July 2001 at 14:54:31, Shashank Tripathi <sub at shanx.com> wrote:
> 
> ST> In the form's "onSubmit()" function, call a function called, say, 
> ST> "checkEntries()". In this function, if required info is 
> not entered, 
> ST> then "return false". This prevents the form from being submitted.
> 
> i thought of this, and the form does validate the entries and 
> if they're not all there the submit is halted.  i can trap 
> the enter key being hit anywhere on the form (onkeypress in 
> the form tag), but that either screws up other validation on 
> the form, or the onclick event is fired anyway...very annoying.
> 
> but the problem is that the first submit button on the page 
> is a 'delete entries' button, and it's this that's being 
> fired...what i would like is some way to have the 
> deleteEntries() function run *only* when the required button 
> is hit, not when the user hits return.
> 
> i could just make the delete buttons into normal buttons and 
> put the values we need to pass through in the querystring, 
> but this seems slightly insecure...and i was hoping for 
> something a bit more elegant! ;>
> 
> hope that's a bit clearer. :>
> 
> darren.


Just thinking out loud here so appologies if this is nonsense :o)

Could you attach an onMouseOver action to the button which sets a
variable to true and then sets that back to false onMouseOut.
When the onSubmit action is called you could check if this variable was
true which would mean that the mouse was over the button when the action
was called - ie in all probabilities the mouse clicked the button not an
enter key being pressed.

Make sense?

Something along the lines of
http://www.cache-22.co.uk/misc/mouseOverForm.htm.

hth

R.Livsey
Lead Programmer for the Tickle Group
Freelance work always welcome
[ PHP | Perl | mySQL | Java ]
work  : www.tickle.co.uk
personal : www.cache-22.co.uk
e : R.Livsey at cache-22.co.uk
m : +447764 685 701
i : 37530949





More information about the thelist mailing list