Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-10-2003, 05:19 PM   PM User | #1
bspahr
New Coder

 
Join Date: Apr 2003
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
bspahr is an unknown quantity at this point
OnClick Event Help

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?
bspahr is offline   Reply With Quote
Old 04-10-2003, 05:24 PM   PM User | #2
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
Change

onClick="return checksubmit()"

to

onsubmit="return checksubmit()"
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”
beetle is offline   Reply With Quote
Old 04-10-2003, 05:37 PM   PM User | #3
bspahr
New Coder

 
Join Date: Apr 2003
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
bspahr is an unknown quantity at this point
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.
bspahr is offline   Reply With Quote
Old 04-10-2003, 05:44 PM   PM User | #4
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
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.
Code:
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
Code:
return confirm( "Are you ready to submit?" );
Always use JS as a backup, and let HTML do the important work.
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”
beetle is offline   Reply With Quote
Old 04-10-2003, 05:54 PM   PM User | #5
bspahr
New Coder

 
Join Date: Apr 2003
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
bspahr is an unknown quantity at this point
Your checkKey function worked perfectly!
Thanks.
bspahr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:08 AM.


Advertisement
Log in to turn off these ads.