Return to Snippet

Revision: 45696
at May 5, 2011 12:11 by genik


Updated Code
$('input[type=text]').keydown(function(e){
	//get the next index of text input element
	var next_idx = $('input[type=text]').index(this) + 1;

	//get number of text input element in a html document
	var tot_idx = $('body').find('input[type=text]').length;

	//enter button in ASCII code
	if(e.keyCode == 13){
		if(tot_idx == next_idx)
			//go to the first text element if focused in the last text input element
			$('input[type=text]:eq(0)').focus();
		else
			//go to the next text input element
			$('input[type=text]:eq(' + next_idx + ')').focus();
	}
});

Revision: 45695
at May 5, 2011 12:09 by genik


Updated Code
$('input[type=text]').keydown(function(e){
	//get the next index of text input element
	var next_idx = $('input[type=text]').index(this) + 1;

	//get number of text input element in a html document
	var tot_idx = $('body').find('input[type=text]').length;

	//enter button in ASCII code
	if(e.keyCode == 13){
		if(tot_idx == next_idx)
			//go to the first text element if focused in the last text element
			$('input[type=text]:eq(0)').focus();
		else
			//go to the next text input element
			$('input[type=text]:eq(' + next_idx + ')').focus();
	}
});

Revision: 45694
at May 5, 2011 12:06 by genik


Updated Code
$('input[type=text]').keydown(function(e){
	//get the next index of text input element
	var next_idx = $('input[type=text]').index(this) + 1;

	//get number of text input element in a html document
	var max_idx = $('body').find('input[type=text]').length;

	//enter button in ASCII code
	if(e.keyCode == 13){
		if(max_idx == next_idx)
			//go to the first text element if focused in the last text element
			$('input[type=text]:eq(0)').focus();
		else
			//go to the next text input element
			$('input[type=text]:eq(' + next_idx + ')').focus();
	}
});

Revision: 45693
at May 5, 2011 12:04 by genik


Updated Code
$('input[type=text]').keydown(function(e){
	//get the next index of text element
	var next_idx = $('input[type=text]').index(this) + 1;

	//get total number text element in a document
	var max_idx = $('body').find('input[type=text]').length;

	//enter button in ASCII code
	if(e.keyCode == 13){
		if(max_idx == next_idx)
			//go to the first text element if focused in the last text element
			$('input[type=text]:eq(0)').focus();
		else
			//go to the next text input element
			$('input[type=text]:eq(' + next_idx + ')').focus();
	}
});

Revision: 45692
at May 5, 2011 11:56 by genik


Initial Code
$('input[type=text]').keydown(function(e){
	//get the current index of text element
	var next_idx = $('input[type=text]').index(this) + 1;

	//get total number text element in a document
	var max_idx = $('body').find('input[type=text]').length;

	//enter button in ASCII code
	if(e.keyCode == 13){
		if(max_idx == next_idx)
			//go to the first text element if focused in the last text element
			$('input[type=text]:eq(0)').focus();
		else
			//go to the next text input element
			$('input[type=text]:eq(' + next_idx + ')').focus();
	}
});

Initial URL

                                

Initial Description
Set focus to all next text input in a html document when press enter button on your keyboard. If  focused at the last text input element, it will be back to the first text input element.

Initial Title
Set Focus To Next Text Input On Press Enter Button

Initial Tags
jquery

Initial Language
jQuery