Return to Snippet

Revision: 22863
at January 24, 2010 22:57 by Meander365


Initial Code
$.fn.focusNextInputField = function() {
	return this.each(function() {
		var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select');
		var index = fields.index( this );
		if ( index > -1 && ( index + 1 ) < fields.length ) {

			fields.eq( index + 1 ).focus();
		}
		return false;
	});
};

Initial URL
http://jqueryminute.com/set-focus-to-the-next-input-field-with-jquery/

Initial Description
I was recently faced with the problem of setting focus to the next input field. The challenge was that I didn’t know what that field was. So given an input field, find the next logical (in the order of the DOM) input field and set focus. I came up with the following jQuery function (plugin) to accomplish this:

Initial Title
Set Focus to the Next Input Field with jQuery

Initial Tags
javascript, forms, jquery, button

Initial Language
jQuery