Is anyone able to help me out,
I have a form and I want the focus to move onto the next field, once the user has entered a value for a form field.
the form has been created using html and css, and would ideally like a javascript event to faciliate this.
I've already tried this and played around with it for a couple of hours but I can't seem to crack it and can't get it to work.
I have attached some code below, to show you my progress. (only html and javascript, there is no CSS styling
any help would be greatly appreciated,
Is there a specific ready why the focus is not moving on to the next field?
<script>
// register jQuery extension
jQuery.extend(jQuery.expr[':'], {
focusable: function (el, index, selector) {
return $(el).is('a, button, :input, [tabindex]');
}
});
$(document).on('keypress', 'input,select', function (e) {
if (e.which == 13) {
e.preventDefault();
// Get all focusable elements on the page
var $canfocus = $(':focusable');
var index = $canfocus.index(document.activeElement) + 1;
if (index >= $canfocus.length) index = 0;
$canfocus.eq(index).focus();
}
});