closure - but still not the current var
<p>I have a problem.. When I alert a var/obj (fields) I don't get the right one returned</p>

<p>Have tried to solve it with a closure, but still the same..</p>

<p>Outside the click() the current and right object (fields) is returned, but not inside</p>

<hr>

<h1>EDIT: jsfiddle</h1>

<p><a href="http://jsfiddle.net/CfxLx/" rel="nofollow">http://jsfiddle.net/CfxLx/</a></p>

<h2>have now made a jsfiddle.. when you want to edit a row and afterwards want to save it, the alertbox returns the id from the row you last pressed edit</h2>

<hr>

<pre><code>this.insert_actions = function(row, id, table, elm, fields, options){
        var actions = $('&lt;div class="actions"&gt;&lt;/div&gt;').appendTo(elm);

        var _this = this;

        if(options.edit){
            alertobj(fields); // alerts object

            var btn_send = $('&lt;input class="btn btn_margin_top" type="button" value="'+Lang.get('BTN_SAVE')+'" /&gt;').appendTo(actions)
                .click(function(){
                    alertobj(fields); // alerts object
                });

                ....
</code></pre>

<h1>with closure</h1>

<pre><code>this.insert_actions = function(row, id, table, elm, fields, options){
        var actions = $('&lt;div class="actions"&gt;&lt;/div&gt;').appendTo(elm);

        var _this = this;

        if(options.edit){
            alertobj(fields); // alerts object

            var btn_send = null;
            (function(fields){
                btn_send = $('&lt;input class="btn btn_margin_top" type="button" value="'+Lang.get('BTN_SAVE')+'" /&gt;').appendTo(actions)
                    .click(function(){
                        alertobj(fields); // alerts object
                    });
            })(fields);

            ....
</code></pre>

<h1>the complete function</h1>

<pre><code>this.insert_actions = function(row, id, table, elm, fields, options){
    var actions = $('&lt;div class="actions"&gt;&lt;/div&gt;').appendTo(elm);

    if(options.edit){
        alert(fields.account_id_.dom.val());
        var btn_send = $('&lt;input class="btn btn_margin_top" type="button" value="'+Lang.get('BTN_SAVE')+'" /&gt;').appendTo(actions)
            .click(function(){
                alert(fields.account_id_.dom.val());
                _this.put_row({
                    id : id
                }, {
                    index : row.index(),
                    insert : true
                }, table, row, fields);
            });

        var btn_cancel = $('&lt;input class="btn btn_light btn_margin_top" type="button" value="'+Lang.get('BTN_CANCEL')+'" /&gt;').appendTo(actions)
            .click(function(){
                _this.get_rows({
                    id : id
                }, {
                    index : row.index()
                }, table, row);
            });

        var Tab = new Tabindex();

        for(var key in fields){
            (function(key){
                Tab.add(key, fields[key]);
                fields[key].dom.keydown(function(e){
                    if(Detect_key.get_keyname(e) == 'ENTER'){
                        btn_send.click();
                    }
                    else if(Detect_key.get_keyname(e) == 'ESC'){
                        btn_cancel.click();

                        return false;
                    }

                    return Tab.press(key, e);
                });
            })(key);
        }
    }
    else{
        var btn_edit = $('&lt;input class="btn" type="button" value="'+Lang.get('BTN_EDIT')+'" /&gt;').appendTo(actions)
            .click(function(){
                _this.get_rows({
                    id : id
                }, {
                    index : row.index(),
                    edit : true
                }, table, row, fields);
            });

        var btn_delete = $('&lt;input class="btn btn_light" type="button" value="'+Lang.get('BTN_DELETE')+'" /&gt;').appendTo(actions)
            .click(function(){
                Dialog.set_dialog({
                    headline : Lang.get('HDL_DELETE'),
                    body : Lang.get('DLG_DELETE_ACCOUNT'),
                    btns : [
                        {
                            value : Lang.get('BTN_DELETE'),
                            func : function(){
                                var A = new Ajax();
                                A.url = 'json.action.php?action=delete_'+table;
                                A.data = {
                                    id : id
                                };
                                A.success = function(response){
                                    if(response.error){
                                        var Cnt = new Content();
                                        Dialog.set_error({
                                            body : Cnt.error_body(response.error),
                                            btns : [
                                                {
                                                    value : Lang.get('BTN_OK'),
                                                    func : function(){
                                                        Dialog.rmv_error();
                                                    },
                                                    focus : true
                                                }
                                            ]
                                        });
                                    }
                                    else{
                                        row.remove();
                                        Dialog.rmv_dialog();
                                    }
                                };
                                A.send();
                            },
                            focus : true
                        },
                        {
                            value : Lang.get('BTN_CANCEL'),
                            func : function(){
                                Dialog.rmv_dialog();
                            },
                            type : 'light'
                        }
                    ]
                });
            });

        actions.css({
            opacity : 0
        });

        row.mouseover(function(){
            actions.fadeTo(0, 1);
        })
        .mouseout(function(){
            actions.fadeTo(0, 0);
        });
    }
};
</code></pre>
