开发者

How to set focus to the next input box onkeyup like tab functionality

开发者 https://www.devze.com 2023-01-13 02:56 出处:网络
I am creating input boxes dynamically to capture inputs fo开发者_StackOverflow中文版r a certain word (e.g. H E L L O for \'hello\'). I want to set focus to the next input box after typing a single cha

I am creating input boxes dynamically to capture inputs fo开发者_StackOverflow中文版r a certain word (e.g. H E L L O for 'hello'). I want to set focus to the next input box after typing a single character in every input box. How should I do this?

<ui:repeat value="#{alphabets}" var="alphabet">
  <h:inputText value="#{alphabet.value}"/>
</ui:repeat>


That will do the trick

// script
function jumpNext(input) {
   $(input).next("input[type=text]").focus();
}


// jsf
<ui:repeat value="#{alphabets}" var="alphabet">
  <h:inputText value="#{alphabet.value}" onkeyup="jumpNext(this)" />
</ui:repeat>

example


It depends on how your HTML structure is. The easiest would it be to give every input an ID (which is always a good idea) and than set the id for the following inpunt in the event handler:

<input id="char1" onkeyup="document.getElementById('char2').focus()" />
0

精彩评论

暂无评论...
验证码 换一张
取 消