Log in

Accessify Forum - Accessibility Discussion

Latest Tweets

W3C Releases Unicorn, an All-in-One Validator http://ow.ly/18jtbB #accessibility #a11y #axs - Gary

3 days ago, RT: @mpaciello RT @w3c

@msmousette You’re welcome, Liz! – @dotjay

22/07/2010

@Elin012 Sorry for delay. The study has now ended. They were after native English-speaking, 18+, not visually or cognitively disabled.

22/07/2010

From @msmousette: “Many thanks to everyone who helped [with the web study] - they had a great response.” –@dotjay

22/07/2010

Native-English speakers: Able to help with a 15 min. accessibility web study? http://www.accessifyfo...@dotjay

21/07/2010

Read more...

Currently Online

No registered users are online.

Preventing form submission with return

  • Reply to topic
  • Post new topic

Home / Site Building & Testing / Preventing form submission with return

Goto page 1, 2  Next

Reply with quote Hey guys.

Here's a quickie.

Is there an accessible method to prevent the enter key from submitting a form, while allowing the enter key to work as normal on focused links and the submit button?

regards

mike 2k:)2
_________________
<marquee><blink><work> webSemantics </work><rest> 2kool2 </rest> &amp; <play> bangers & mashed </play></marquee></blink>
Reply with quote Capture the event and prevent the form submission by returning false (which is not the only way of doing it, but the simplest in this case)

http://www.quirksmode.org/...

Let me know if you need an example. I don't know how familiar with Javascript you are?

I suspect you're really after a scriptless solution, in which case I can't think of any. Confused
Reply with quote Well you could capture the submission server-side, then re-present it filled in, and take no further action. If you had the Javascript you described, that would prevent submission in the first place for most, yet cover the case for those who did not have Javascript enabled.
Reply with quote
kiwibrit wrote:
Well you could capture the submission server-side, then re-present it filled in, and take no further action. If you had the Javascript you described, that would prevent submission in the first place for most, yet cover the case for those who did not have Javascript enabled.


True, though that does seem a lot of work for very little gain.

If it's not being too nosy, can I ask why you want to do this Mike? Are you simply trying to prevent accidental submission of the form, or is this something more fundamental than that?
Reply with quote What happens if you set another elements accesskey to enter? If possible.

Not sure this is a very accessible thing to be doing though. But I don't know the situation...
_________________
creator of Talklets
Talklets ,
Reply with quote Hi guys, thanks for the replies,

I am looking for a client side JavaScript solution.
It's a large data entry type form and the biggest user "mistake" is pressing return while in an input text field.
Not the end of the world but it's very irritating to the user who has to wait for the server response.

I've been toying with placing onsubmit="return false" in the form element and adding onclick="check_and_submit()" to the submit button.
Though I'm unhappy with the consequences of this method.

I tried using a simple event trap to test keyboard for 13 (Enter / return).
But couldn't get it to work cross browser, and didn't get as far as limiting it's scope.


Torsten,

My JavaScript is quite good (level 5 plus).
I'm just working through the article posted (advanced events).
If you have any examples that would be brilliant.

regards

mike 2k:)2
_________________
<marquee><blink><work> webSemantics </work><rest> 2kool2 </rest> &amp; <play> bangers & mashed </play></marquee></blink>
Reply with quote What about popping up a simple confirmation dialogue on form submission e.g. "Are you sure you want to submit", or something to that effect?
Reply with quote [ot]

mike 2k:)2 wrote:
My JavaScript is quite good (level 5 plus).


Level 5?

[/ot]
Reply with quote
mike 2k:)2 wrote:
I tried using a simple event trap to test keyboard for 13 (Enter / return).
But couldn't get it to work cross browser, and didn't get as far as limiting it's scope.


Due to various problems, a temp solution for the search was put in place on www.macmillan.org.uk, if you check the the opensearch.js file near the bottom, it's got just what you're after.

Attaching that type of event to just the inputs (although not the submit obviously) should sort it out.
_________________
Nomensa / AlastairC
Reply with quote Alastc, thanks, I'll check it out.

Bill, the six levels of javascript though I've seen a seventh proposed somewhere. It's quite funny.
_________________
<marquee><blink><work> webSemantics </work><rest> 2kool2 </rest> &amp; <play> bangers & mashed </play></marquee></blink>


Last edited by mike 2k:)2 on 15 Mar 2007 04:08 pm; edited 1 time in total
Reply with quote To disable it completely use the OnKeyDown handler on the <body> tag and use the following javascript:-

Code:
if (window.event.keyCode == 13)
{
    event.returnValue=false;
    event.cancel = true;
}


p.s. checkout http://www.beansoftware.com/... for pure asp.net solutions and variations.
Reply with quote Hi Devastated,

Tried that but it doesn't work cross browser.
_________________
<marquee><blink><work> webSemantics </work><rest> 2kool2 </rest> &amp; <play> bangers & mashed </play></marquee></blink>
Reply with quote
mike 2k:)2 wrote:
Tried that but it doesn't work cross browser.


I think it's the cancelbubble/stopPropagation and preventDefault that are needed... (and in the example I mentioned). But I'm only a level 4, so do check it Wink
_________________
Nomensa / AlastairC
Reply with quote I use the following function to cancel events in IE, Firefox, Opera and Safari. Just call it with the event that you want to cancel.

Code:
function cancelEvent(e) {
    if (e && e.preventDefault) {
        e.preventDefault();
    }
    return false;
}

_________________
Jim O'Donnell
work: Royal Observatory Greenwich
play: eatyourgreens
Reply with quote Have you got this cracked yet? I've been meaning to tinker with this all day and I've only just got around to it.

This works in all the browsers I have access to at the mo (O9, FF 2 and IE6) though it's not very elegant and may not play well with other scripts.

Code:
  window.onload = function() {
 
    var textfields = document.getElementsByTagName('input');
   
    for (var i=0, count=textfields.length; i<count; i++) {
      if (textfields[i].type == 'text') {
        textfields[i].onkeypress = function(e) {
          if (!e) var e = window.event;
          if (e.keyCode == 13) return false;
        }
      }
    }
  }

Goto page 1, 2  Next

  • Reply to topic
  • Post new topic

Display posts from previous:   

All times are GMT

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum