views:

88

answers:

3

i use recaptcha

Recaptcha.create("xxx", "recaptcha", {
            theme: 'clean',
            tabindex: 0,
            callback: $("#id").focus
        });

i want to use callback to focus some field, but it doesn't work, only callback: f works

 function f() {
        $("#FIO").focus();
    }

what is the problem?

+3  A: 

The callback needs to be a function. What you have attempts to execute the $() function and reference the focus method of it. That won't work. Try this.

Recaptcha.create("xxx", "recaptcha", {
        theme: 'clean',
        tabindex: 0,
        callback: function() { $("#id").focus(); }
    });
tvanfosson
A: 

Are you sure the result of the statement $("#FIO").focus() is consistent across scopes?

or try this?callback: function() { $("#FIO").focus(); }

SHiNKiROU
A: 

The focus() is also native function of javascript, you can do in either way

callback: function(){$("#id").focus();}

or

callback: function(){$("#id")[0].focus();}
Sarfraz