Forum Moderators: open

Message Too Old, No Replies

Tab = Enter

         

yllai

5:25 am on May 10, 2007 (gmt 0)

10+ Year Member



Hi all,

In browser form, when we want to move from the first textbox to another/ next textbox, we press TAB key. Can I know whether we can change the interaction as press ENTER key to goto the another/ next textbox? If can, how to do? Any sample?

Wish to receive any reply ASAP. Thanks in advanced.

vincevincevince

5:29 am on May 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So far as I know, the way to do this is to use a single line <textarea> instead of <input type="text"> and then check for the newline character with each key-press event... if you find one then move the focus using javascript to the next element.

Warning - there is probably a much better way...

Xapti

5:33 am on May 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How could there be a better way? that's the only way I see.

for whatever reason (I'm not saying he can't explain things, nor thinking you're stupid) if you didn't understand him, he just said use JavaScript to check when the user presses Enter, and every time he does, set focused element to the next one.

I really don't see much of a point for this function though. Anyone who wants to navigate to the next object should just use the TAB key!
If they don't know that function exists, let them know!

Because a useful feature of tabbing is SHIFT-tabbing, which makes you move BACKWARDS in objects focus. You'd need to add even MORE scripting if you wanted to do this with Enter. Shift-enter is also a forced line break (without submitting), which may not really cause any problems, but something you should keep in mind.

[edited by: Xapti at 5:36 am (utc) on May 10, 2007]

vincevincevince

5:39 am on May 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A cleaner way would be to change the form submit function to something like: onSubmit="if (confirm('Sure you want to submit?')) {return true;} else {return false;}"

Note that I'd be very concerned about disabling the normal Enter functionality. Spare a thought for those who rely upon screen-readers and who depend upon the standard things such as tabbing between fields and pressing enter or ctrl-enter to submit.

Dabrowski

10:45 am on May 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look at this thread:
[webmasterworld.com...]

Capture the keyboard events, when you find an enter (code is 13), switch focus to your next box, and return false to prevent the form submitting.