This is only set up to work in FF, and only tested in FF2, but it will
auto-tab to the next input field. It may need some more work if you're doing
more deeply nested elements(ie, you may want to use some root element
instead of element.parentNode), but it should be a decent starting point.
-Jerod
<html>
<head>
<script type="text/javascript">
function enter(e, element) {
if(e && e.keyCode == 13) {
var inputs = element.parentNode.getElementsByTagName("input");
var next = null;
for(var i=0;i<inputs.length-1;i++){ //-1 is so we don't focus past
the end of the list
if(inputs[i] == element){
next = inputs[i+1];
}
}
next.select();
next.focus();
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form action="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi"
name="demo">
<input type="hidden" name="hiddenfield" value="42">
Field 1: <input type="text" name="field1" id="_field1" onkeydown="return
enter(event,this)"><br>
Field 2: <input type="text" name="field2" id="_field2" onkeydown="return
enter(event,this)"><br>
<input type="submit" name="send">
</form>
</body>
</html>
On 2/19/07, Christophe Porteneuve <[EMAIL PROTECTED]> wrote:
>
>
> Hey Janko,
>
> Janko Mivek a écrit :
> > Anyway, because I have control on tabulation order on server I decided
> > to let the server write a script to tab into a right next element. This
> > is still better because I think have more control on tabulation than
> > from JS.
>
> I have *no idea* what you mean. Tabulation is obviously a UI issue,
> hence client-side. What the server side could do for you, I can't begin
> to guess.
>
> I only suggested the server side makes sure tab-accessible form elements
> are provided with appropriate tabindex= attributes, so that the
> client-side script could use them to tab on Return keys.
>
> --
> Christophe Porteneuve aka TDD
> [EMAIL PROTECTED]
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---