Can you please tell me how to move focus on to the next field when the enter key is press? I use the dform
plugin (which converts JSON to a form).
I Googled it, but this not working. Why doesn't my focus move on to the next field?
JSFiddle: http://jsfiddle.net/5WkVW/1/
$(document).keypress(function(e) {
if(e.which == 13) {
// Do something here if the popup is open
alert(dd)
var index = $('.ui-dform-text').index(this) + 1;
$('.ui-dform-text').eq(index).focus();
}
});
<script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.0/jquery.min.js></script>
<form id=testSuiteConfigurationform name=testSuiteConfigurationform method=post class=ui-dform-form novalidate=novalidate>
<label class=ui-dform-label>
<h3>Configuration Parameters</h3>
</label>
<div class=ui-dform-div inputDiv>
<fieldset class=ui-dform-fieldset>
<input type=text id=totalRetryCount name=totalRetryCount tabindex=1 onblur=validateElement('Configuration', 'testSuiteConfigurationform','totalRetryCount') class=ui-dform-text valid>
<legend class=ui-dform-legend>Total Retry Count</legend>
<label for=totalRetryCount class=checked>✔</label>
</fieldset>
<fieldset class=ui-dform-fieldset>
<input type=text id=totalRepeatCount name=totalRepeatCount tabindex=2 onblur=validateElement('Configuration', 'testSuiteConfigurationform','totalRepeatCount') class=ui-dform-text>
<legend class=ui-dform-legend>Total Repeat Count</legend>
</fieldset>
<fieldset class=ui-dform-fieldset>
<select id=summaryReportRequired name=summaryReportRequired tabindex=3 onblur=validateElement('Configuration', 'testSuiteConfigurationform','summaryReportRequired') class=ui-dform-select>
<option class=ui-dform-option value=true>true</option>
<option class=ui-dform-option value=false>false</option>
</select>
<legend class=ui-dform-legend>Summary Report Required</legend>
</fieldset>
<fieldset class=ui-dform-fieldset>
<select id=postConditionExecution name=postConditionExecution tabindex=4 onblur=validateElement('Configuration', 'testSuiteConfigurationform','postConditionExecution') class=ui-dform-select>
<option class=ui-dform-option value=ALWAYS>ALWAYS</option>
<option class=ui-dform-option value=ON_SUCCESS>ON_SUCCESS</option>
</select>
<legend class=ui-dform-legend>Post Condition Execution</legend>
</fieldset>
</div>
</form>
*Note (from comments): It also needs to work on pages that do not have tabindex
values set