...

View Full Version : OnClick Event Help



bspahr
04-10-2003, 05:19 PM
I have the following form:
http://www.htc.net/~jspahr/form.htm


I want the first 3 questions to be required:
* Troop # (required)
* District (required)
* Neighborhood (required)

Currently, it brings up the alert as soon as you click into the text field.
Is there a way to have this checked when the user clicks on the submit button instead?

beetle
04-10-2003, 05:24 PM
Change

onClick="return checksubmit()"

to

onsubmit="return checksubmit()"

bspahr
04-10-2003, 05:37 PM
I tried that.

The only problem is that I am using:

onClick="document.ac2003.submit()"

to submit the form.



I need to be able to prevent the user from accidentally submitting
the form with the enter button also.

beetle
04-10-2003, 05:44 PM
Well, giving the user no way to submit the form if they have Javascript turned off is a Bad Idea™

There's other ways to disable the enter-key-submission.


function checkKey( e )
{
var kc = ( e ) ? e.which : event.keyCode;
return ( kc != 13 );
}

<form ... onkeypress="return checkKey()" ... >
Or, include a confirmation in your validation script at the end
return confirm( "Are you ready to submit?" );Always use JS as a backup, and let HTML do the important work.

bspahr
04-10-2003, 05:54 PM
Your checkKey function worked perfectly!
Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum