Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

focus() doesn't work inside colorbox pop-up

I tried to use focus for first input field on the form. but it doesn't work. When I call attr("id") for that input it worked. When I call focus for the same input, I didn't see any result. I also tried to use native Javascript. Does anyone know how to fix that?

like image 683
Yura Burko Avatar asked Mar 01 '11 12:03

Yura Burko


3 Answers

You are all misunderstanding the question. When Colorbox opens you can't focus an input field?

...unless you add your focus to the Colobox onComplete key e.g.

$('#mydiv a').colorbox({ onComplete:function(){ $('form input:first').focus(); }});

You could also bind the focus to an event hook:

$('#mydiv a').bind('cbox_complete', function(){
        $('form input:first').focus();
});

That should be enough to get started.

like image 96
HGPB Avatar answered Sep 23 '22 18:09

HGPB


use

$(document).ready(function() {
       // focus on the first text input field in the first field on the page
        $("input[type='text']:first", document.forms[0]).focus();
    });
like image 32
diEcho Avatar answered Sep 22 '22 18:09

diEcho


It may be happening that when your colorbox is opened its focus goes onto the highest element i.e. body of page. use document.activeElement to find that focus went to which element. Then find iframe or id of your colorbox and then set focus on it

like image 33
Ishan Tiwari Avatar answered Sep 22 '22 18:09

Ishan Tiwari