0

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;
});
user197674
  • 748
  • 2
  • 7
  • 22

2 Answers2

1
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);
Naftali
  • 144,921
  • 39
  • 244
  • 303
0

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

Ben Madsen
  • 101
  • 1
  • 4