Most JavaScript engines will treat:
var ti = $("#txtArea").attr('tabindex') + 1;
as concatenation, not addition, so the ti
variable has "1"
appended to it's initial value. The solution is to parse ti
to a number before attempting to increment it, or to use an operator specifically designed to increment it (which will convert the string to a number in the process).
var ti = parseInt($("#txtArea").attr('tabindex'), 10) + 1;
or
var attr = $("#txtArea").attr('tabindex'),
ti = attr++; // caveat here is that, if ti = 1, attr will be 2
otherwise you'll be trying to focus $('[tabindex=11]')
, instead of $('[tabindex=2]')
;