tags:

views:

38

answers:

0

Error: s.currentBox is not defined, although container.onclick is firing before buttons[i].click

var InputDigit = function(container,value, onchange){
    this.init(container,value, onchange);
};

InputDigit.prototype = {        
    currentBox: null,
    init: function(container, value, onchange){ 
        var self = this;

        container.onclick = function(){ 
            self.currentBox = this;         
            self.inputBoxClicked(this);
        };      

        //init click event for inputboxes
        var buttonsContainer = document.getElementById('inputButtons');
        var buttons = buttonsContainer.getElementsByTagName('div');

        for(var i=0; i<buttons.length;i++){
            (function(s){
                buttons[i].onclick = function(){
                    var innerVal = isNaN(this.innerHTML)  ? '' : this.innerHTML;
                    s.currentBox.innerHTML = innerVal;  //GETTING ERROR s.currentBox undefined
                    s.hideOverlay();
                };
            })(self);
        }
    }
};