Search code examples
javascriptjeditable

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;
});

Solution

  • 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);