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 15 of 15
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stopping <Enter> from submitting in Netscape

    I am using the following function to prevent the user from submitting a form with the enter key. It work fine in IE, but not in Netscape. Anyone know of a fix for this?


    <script type="text/javascript">
    function checkKey( e )
    {
    var kc = ( e ) ? e.which : event.keyCode;
    return ( kc != 13 );
    }
    </script>


    <form onkeypress="return checkKey()">
    <input type="text" name="" />
    <input type="submit" name="Submit" value="Submit" />
    </form>

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Which version of netscape? You always have to specify that these days as NS4.x and NS6+ are two different beasts.
    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
    Jul 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    NS6+

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oops. Sorry, I forgot the event only gets passed with script-assigned events.

    This should work
    Code:
    <script type="text/javascript">
    
    function checkKey( e )
    {
        var kc = e.which || e.keyCode;
        return ( kc != 13 );
    }
    
    </script>
    
    
    <form onkeypress="checkKey( event )">
    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
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stopping <Enter> from submitting in Netscape

    Originally posted by bspahr75
    I am using the following function to prevent the user from submitting a form with the enter key.
    I strongly advise against this. If you prevent the enter key from submitting a form you're making it inaccessible to people who don't use a mouse. Remember that some people can't use a mouse.

    Why, in any case, would you want to do this?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #6
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey bcake, I thought you might be popping in here

    I think this is another case of the client making a fairly adamant request. Since you're an accessibility guy, tell me this: would it be kosher to allow enter-key submissions when the Submit button has focus, but at no other time?

    I have no concept of how many people know/don't know that the enter key will submit a form.
    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”

  • #7
    New Coder
    Join Date
    Jul 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I doesn't work on Netscape 6.2.3

  • #8
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey, bspahr75, throw me a bone here. At least tell me what error message you are getting.

    Any feedback on the accessibility issue brothercake raised?
    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”

  • #9
    New Coder
    Join Date
    Jul 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am not getting any error.

    You were right about the unreasonable client request.

    They just don't want anyone to be able to submit the form accidentally by pressing the enter key.

    Don't most people use the tab key anyway?

  • #10
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by beetle
    HI think this is another case of the client making a fairly adamant request. Since you're an accessibility guy, tell me this: would it be kosher to allow enter-key submissions when the Submit button has focus, but at no other time?
    I don't think so; it would certainly be better, but I see no valid reason for doing it at all - by catering for one potential problem, you create another actual problem, and a far more serious problem to boot. Lots of people use tab to navigate and enter to submit a form - power users as much as disabled visitors.

    I would offer no compromise - the client is wrong. Point them towards the requirements of Section 508 of the Americans with Disabilities Act; they have no choice but to comply.
    Last edited by brothercake; 04-11-2003 at 06:06 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #11
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Werd. I agree.

    Maybe use the confirm message I suggested earlier?
    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”

  • #12
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by beetle
    Werd. I agree.
    Is that so weird?

    I recommend pre-processing the form - send the data to a page which displays it and says "is all of this okay"? or something. Then you give two options - "yes, submit this information" or "no, take me back to my form".
    Last edited by brothercake; 04-11-2003 at 06:12 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #13
    New Coder
    Join Date
    Jul 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, is probably the best way to go.

  • #14
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "Premature" form submission would mean that not all the fields were filled. So what's wrong with making sure that all the required fields have a valid value (and submit form only when they do) regardless which way ("enter" key or "submit" button) it was submitted.

    Look in the ROOT of the problem
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #15
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Vladdy
    "So what's wrong with making sure that all the required fields have a valid value (and submit form only when they do)
    Nothing wrong; an excellent solution.

    But mine has an added usability benefit - once the form is submitted users get a second chance to make sure it's all okay - my experience is that reading what you wrote in a read-only output is more crystalising than reading it in an edit box. It's particularly useful for when you're sending precise data - like credit card numbers - or selecting from a complicated set of options.

    I guess it depends; might be overkill for a very simple form.

    Or you could do both - alert for missing data and post to a "confirm or edit" page. afaik there are no accessibility problems inherent with javascript alerts - but you do have to do something useful with the return ...

    ... CF is actually a rather bad example of this (ahem ) - when you click "login" it says "please scroll to the bottom of this page" The link should take you to the login form - using an anchor for non-JS browsers, or sending focus to the first element for JS browsers.
    Last edited by brothercake; 04-11-2003 at 06:43 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

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