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()" />
精彩评论