I have a form, and I am able to get all form elements through serializeArray()
.
I want to focus()
on form elements based on their tabindex value using enter key. Only if it has value in it or else focus on itself.
Little new to jQuery so if any mistakes...
$.fn.entertab = function()
{
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
var maxTabIndex = 20;
var elements = this.serializeArray();
$.each(elements, function(i, element)
{
this.keypress(function(e){
var nTabIndex=this.tabIndex;
var myNode=this.nodeName.toLowerCase();
if(nTabIndex > 0 && key == 13 && nTabIndex <= maxTabIndex && ((!myNode.attr("disabled")) || (myNode.val == "")))
{
myNode.focus();
}
else
{
nTabIndex=this.tabIndex+1;
myNode.focus();
}
});
});
}
$("theform").entertab();
You can also try this HTML
SCRIPT ///////////
////////////// Worked Fine in EI,Chrome, Mozilla . not tested in safari and other browser
I think I understand what you want to do. I rewrote your code and ended up with this:
There's a working example on jsFiddle.