user197674
user197674

Reputation: 798

Access to other variables inside of jeditable

I'm really new to javascript, so sorry for my ignorance. In jeditables, you can specify a callback function. I'm using all this code in a separate script. Is there a way to pass variables into this callback function? for example: var info = "foo";

$('#bar').editable("/foo/bar",
    callback : function(value, settings) {
        var foobar = value + info;
});

Upvotes: 0

Views: 189

Answers (2)

Ben Madsen
Ben Madsen

Reputation: 101

You can also assign attributes to the "settings" object as follows:

$(".myClass").editable( "/foo/bar",
{
    indicator: "Saving...",
    tooltip: "Click to edit",
    onblur: "submit",
    bax: bax
},
function(value, settings) {
    var foobar = value + settings.bax;
});

Inside your handler, you can see the use of the reference to the object by simply stating settings.bax

Upvotes: 0

Naftali
Naftali

Reputation: 146360

var info = "foo";
$('#bar').editable("/foo/bar",
    function(value, settings) {
        var foobar = value + info;
});

You should read up on javascript scoping.

What I did above is not usually the way to go since info is now in the global scope.


Side point:

You can even move you callback to a completely different location:

var info = "foo", 
    callBackFn = function(v, s){
         var foobar = v + info;
    };
$('#bar').editable("/foo/bar",  callBackFn);

Upvotes: 1

Related Questions