user6458249
user6458249

Reputation:

how can i focus to the new element ...By pressing the Tabbutton

How Can I focus to the new Element pressing the TAB

 var objClass = obj.className;
        $(obj).datepicker({
            changeMonth:true,
            changeYear:true,
            onClose:function()
            {

              $("#ui-datepicker-div").css("visibility", "hidden");
              focusToNextField();         
            }

Upvotes: 0

Views: 91

Answers (4)

Jai
Jai

Reputation: 74738

I suppose you need to have a keydown event:

$(obj).datepicker({
    changeMonth: true,
    changeYear: true,
    onClose:function() {
        $("#ui-datepicker-div").css("visibility", "hidden");
        // focusToNextField();       
    }
}).on('keydown', function(e){
   e.preventDefault();
   if(e.which === 9){
     $(this).next(':input').focus();
   }
});

Upvotes: 0

Nishant123
Nishant123

Reputation: 1966

Use .attr("tabIndex", "-1")

$('#dateelement').datepicker({
    changeMonth: true,
  changeYear: true,

}).next('button.ui-datepicker-trigger')
      .attr("tabIndex", "-1");

Here is the demo

Observe the cursor moves to the next textbox on hittin TAB button

Upvotes: 2

Dhara Parmar
Dhara Parmar

Reputation: 8101

Use $(":focusable") to get current element and add focus on next element

var objClass = obj.className;
$(obj).datepicker({
    changeMonth: true,
    changeYear: true,
    onClose:function() {
        $("#ui-datepicker-div").css("visibility", "hidden");
        var focusables = $(":focusable");   
        var current = focusables.index(this),
        next = focusables.eq(current+1).length ? focusables.eq(current+1) : focusables.eq(0);
        next.focus();
    }

});

Upvotes: 0

nayeri
nayeri

Reputation: 175

You could use $('#nextElem").focus();

Upvotes: 0

Related Questions