Click to See Complete Forum and Search --> : Substituting RETURN with TAB


GeoffS
08-07-2003, 09:50 AM
Think this must be a dumb question but anyway.

I have a form with a number of fields. If after filling a field the user hits RETURN rather than TAB, the form gets submitted. Is there a way to replace the RETURN with TAB using JavaScript or is there some simpler way of only allowing submission when the 'SUBMIT' button is clicked?

Thanks

AdamBrill
08-07-2003, 10:19 AM
Instead of your submit button, put this:

<input type=button value="Submit!" onclick="this.form.submit();">

Charles
08-07-2003, 02:22 PM
Originally posted by AdamBrill
Instead of your submit button, put this:

<input type=button value="Submit!" onclick="this.form.submit();"> That is bad, very bad. You'll end up with a form that cannot be submitted by the 13% of users that do not use JavaScript. And I think your users are smart enough to know that their browser will submit the form if they hit return. Some of them may even hit return when they want the form submitted. It's not a good thing to go about messing with the expected user interface

GeoffS
08-07-2003, 02:51 PM
Charles - Interesting. Agree on not stopping non JavaScript enabled browsers from submitting. If not all fields are filled then the server side will throw back an error. I liked the idea of converting to stop that happening if JavaScript was enabled (assume it would just submit if JavaScript not enabled). Often forget and input RETURN myself so auto-changing it to TAB where appropriate would benefit me.

Anyway, still don't know how to do it because I don't know whether (and if so how) I can change the keycode in JavaScript.

boojum
08-07-2003, 03:06 PM
just do what adam said and stick a submit input in a <noscript>

are there really no readers that can interpret javascript?

AdamBrill
08-07-2003, 05:05 PM
Originally posted by boojum
are there really no readers that can interpret javascript? If you talking about screen readers, yes, they can interpret JavaScript. I downloaded one once to check if what everyone always says about nothing working in screen readers was true, but it wasn't... Everyone that has JavaScript turned off turned it off themselves or just has a browser that doesn't support it(which is not all screen readers).

GeoffS
08-08-2003, 04:43 AM
OK - looks like I could get a solution via route suggested but am still wondering about the implicit question I asked.

Given a keypress event can I change the keystroke that is processed (could apply to changing case instead of changing RETURN to TAB)? If so, could somebody point me at an example?

Thanks

Charles
08-08-2003, 05:06 AM
Originally posted by AdamBrill
If you talking about screen readers, yes, they can interpret JavaScript. I downloaded one once to check if what everyone always says about nothing working in screen readers was true, but it wasn't... Everyone that has JavaScript turned off turned it off themselves or just has a browser that doesn't support it(which is not all screen readers). And I've tested a graphical browser and found that you can use CSS to change the colors of the scrollbars so I suppose that it will work on all graphical browsers.

Adam, just because you found one screen reader that supports JavaScript it doesn't follow that all or most or even that more than one supports JavaScript.

AdamBrill
08-08-2003, 07:24 AM
Well, I can tell this is going to be an endless battle... ;) Your probably right, though, that it doesn't work in all screen readers. However, I have never seen you point out that if you use CSS for layout, it won't work in all browsers(actually, it probably works in fewer browsers than if you would use tables)... It's hard for me to comprehend how people would go for standards over what is going to work for the most of their users.

BTW, if the screen reader that I tried is the only one that supports any of those things, don't you think that everyone would get that screen reader? Why would they get a different one that doesn't support any of it, since most sites DO use tables and JS?

AdamBrill
08-08-2003, 07:31 AM
Oh, BTW, here is an example, GeoffS:<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function key_pushed(event){
if(event.keyCode==13){
event.keyCode=9;
}
}
</script>
</head>
<body onKeyDown="key_pushed(event);")>
<form>
<input type=text>
<input type=text>
<input type=submit>
</form>
</body>
</html>That will convert the <enter> key to a tab button. :D

GeoffS
08-08-2003, 10:04 AM
Adam - Thanks

Will retire rapidly from the theological debate;)

Charles
08-08-2003, 02:08 PM
Originally posted by AdamBrill
However, I have never seen you point out that if you use CSS for layout, it won't work in all browsers Actually I have, at least by implication. I have always insisted that one must start with a page that works and then add the CSS and I have often drawn attention to the priority 1 accessibility guideline:6.1 Organize documents so they may be read without style sheets. For example, when an HTML document is rendered without associated style sheets, it must still be possible to read the document. [Priority 1]
When content is organized logically, it will be rendered in a meaningful order when style sheets are turned off or not supported.
http://www.w3.org/TR/WCAG10/wai-pageauth.html#tech-order-style-sheets

And I have discussed at length elsewhere why using TABLEs for lay out makes your page not work on screen readers that do understand TABLEs.