Search code examples
jquerystringscroller

jQuery Spinner that can display string and number values?


So I want to create a jQuery spinner that increments when clicked but if its value is 0 (or any targeted value, but lets go with 0 ) I want it to display the word 'unlimited' instead of 0, and then when incremented start counting as if 0 was a number, so it will read: unlimited, 1,2,3,4, etc. Is there any way to do this? Ive found methods for counting through the alphabet and the like but changing one value to a string seems rather difficult. here is a fiddle of a basic spinner:

var spinner = $( "#spinner" ).spinner();
$( "#spinner" ).spinner({
    min: -1,
    max: 50,
});

http://jsfiddle.net/nmnx0y7a/1/


Solution

  • One more version:

    $("#spinner").spinner({
        min: -1,
        max: 50,
        spin: function(e, ui) {
            if (ui.value == 0) {
                e.preventDefault();
                this.value = "unlimited"
            }
        }
    })
    .val('unlimited');
    

    Demo: http://jsfiddle.net/nmnx0y7a/9/