Hello everyone.

I am trying to modify the SpinButton code (from here
http://www.softwareunity.com/sandbox/jqueryspinbtn/) to include a
callback when the value is changed.

I'm very new to callback functions and have tried searching the web
for how to add them but so far have had no luck.

My desired goal is to be able to pass a function or not and if the
function is included have it executed when the spinner button is
clicked.

Here is what I have tried (along with the original code):

$.fn.SpinButton = function(cfg){
        return this.each(function(){

                // Apply specified options or defaults:
                // (Ought to refactor this some day to use $.extend() instead)
                this.spinCfg = {
                        //min: cfg && cfg.min ? Number(cfg.min) : null,
                        //max: cfg && cfg.max ? Number(cfg.max) : null,
                        min: cfg && !isNaN(parseFloat(cfg.min)) ? 
Number(cfg.min) :
null,   // Fixes bug with min:0
                        max: cfg && !isNaN(parseFloat(cfg.max)) ? 
Number(cfg.max) : null,
                        step: cfg && cfg.step ? Number(cfg.step) : 1,
                        page: cfg && cfg.page ? Number(cfg.page) : 10,
                        upClass: cfg && cfg.upClass ? cfg.upClass : 'up',
                        downClass: cfg && cfg.downClass ? cfg.downClass : 
'down',
                        reset: cfg && cfg.reset ? cfg.reset : this.value,
                        delay: cfg && cfg.delay ? Number(cfg.delay) : 500,
                        interval: cfg && cfg.interval ? Number(cfg.interval) : 
100,
                        _btn_width: 20,
                        _btn_height: 12,
                        _direction: null,
                        _delay: null,
                        _repeat: null,
                        callback: function(){} /* I added this*/
                };
                this.adjustValue = function(i){
                        var v = (isNaN(this.value) ? this.spinCfg.reset :
Number(this.value)) + Number(i);
                        if (this.spinCfg.min !== null) v = Math.max(v, 
this.spinCfg.min);
                        if (this.spinCfg.max !== null) v = Math.min(v, 
this.spinCfg.max);
callback(); /* I added this)
                        this.value = v;
                };





when trying to run this I get callback is not defined.

Any help is greatly appreciated!!!

Reply via email to