Reputation: 79
i have a JSf file where multiple text filed. I want when i press "TAB" key next filed with previous filed value.Any help or code material help me thansk in advance.
<h:column>
<f:facet name="header">
<h:outputText value="Subno To" />
</f:facet>
<h:inputText id="mnpSubNoTo_id1" value="#{item.subNoFrom}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Error Status" />
</f:facet>
<h:inputText id="mnpErrorStatus_id1" value="#{item.subNoTo}" />
</h:column>
i want in this code when in enter text in filed id = "subNoFrom" and press tab next field id="mnpErrorStatus_id1" auto fill with id = "subNoFrom" field value. Any help regarding will be highly appricate!!!
Upvotes: 1
Views: 1166
Reputation: 7395
Add onkeydown
event to your first textbox
as below.
<h:inputText id="mnpSubNoTo_id1" value="#{item.subNoFrom}" onkeydown="func(event)"/>
Your javascript
code should be like this.
<script>
function func(e) {
var txt1 = e.target || e.srcElement;
var key = e.keyCode ? e.keyCode : e.charCode
if(key == 9) {
var value1 = txt1.value;
var lastIndex = txt1.id.lastIndexOf(":");
var txt2Id = txt1.id.substring(0, lastIndex) + ":mnpErrorStatus_id1";
document.getElementById(txt2Id).value = value1;
}
}
</script>
Upvotes: 2