Reputation: 3
I would like to make a focus to the next input in a table with jquery. I have this table in jsf.
<p:dataTable id="resu" value="#{onController.items}" var="item" >
<p:column id="colIn" >
<h:inputText id="i" value="#{item.cup}" />
<p:column>
<p:dataTable>
was tested with this:
function nexts(input) {
$(input).next("input[type=text]").focus();
}
onkeyup="nexts(this)"
in the input
It does not work between rows only with inputs followed.
Upvotes: 0
Views: 4657
Reputation: 1108782
The next()
only searches in the siblings. The datatable renders a HTML <table>
with rows in <tr>
elements. Rightclick the page in webbrowser and choose View Source. You should base your JS/jQuery code on this (simply because that's basically all what it can see). Technically, you should go up to the closest <tr>
, then go to the next <tr>
and finally find the next input element in there.
$(input).closest('tr').next('tr').find('input[type=text]').focus();
Upvotes: 1