views:

361

answers:

2

A basic HTML question. Is it possible on an HTML page to declaratively achieve a behavior when pressing Enter in a textbox moves the focus to the next control? How do you achieve it and how do you turn it off? Or maybe the dynamic javascript part should be involved here?

For exaple, the following HTML in IE7 does not allow to move to the focus to the next textbox with enter:

<html>
<body>
<form>
<table>
<tr><td>
<input type="text" name="i1"/>
<td></tr>
<tr><td>
<input type="text" name="i2"/>
<td></tr>    
</table>
</form>
</body>
</html>

I have a page where I need to get rid of this 'move the focus to the next control when Enter is pressed' behavior.

@Edit: The example above turns out to be incorrect. The control the focus jumps to when I press enter on the page I want to avoid this behavior on is actually of type submit. The strange thing is that this "submit" is a part of a Telerik tree control and is not a submit button but an arrow used to collapse and expand the tree structure. So I assume the focus jumps to the next submit control which the Browser expects to be a normal submit button which is not true in my case.

So I suppose I should look for a Telerik pecific solution here.

A: 

<input type="text" name="i1" Tabindex="[order number]"/>

I usually lookup these things on: http://start.gotapi.com/

Michael MacDonald
The question is not how to set the tab order but what determines the focus change on pressing Enter.
axk
+1  A: 

In most browsers, pressing Enter when focused within a form will submit the form. If you need to change this behavior so that pressing Enter moves to the next textbox you will need to use javascript.

Try this: (courtesy of javascript.internet.com)

http://javascript.internet.com/forms/tab-key-emulation.html

aweber1
Thanks for the suggestion, in fact this is what happens - the focus moves to the input control with type "submit"
axk