Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2003
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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”

  • #3
    New Coder
    Join Date
    Apr 2003
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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”

  • #5
    New Coder
    Join Date
    Apr 2003
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your checkKey function worked perfectly!
    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •