Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery spinner initial value not getting set

I am using JQuery spinner control on my web form. But it's initial value is not getting set. I am using IE9 + VS2010

Here is the code I have written in my common function. I call this function at run time and send parameters accordingly.

function(spinnerid, minval, maxval, initvalue, step) {
$("#" + spinnerid).spinner({ min: minval, max: maxval, increment: step, value: initvalue });
}

These are the libraries I use:

<script type="text/javascript" src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<link type="text/css" rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />

And this is the HTML code:

<input type="text" id="income" class="income" />
like image 348
Anil Soman Avatar asked Oct 26 '12 12:10

Anil Soman


2 Answers

I don't know why the value option isn't working as documented. I've tried it myself and have the same problem. This will solve your issue though...

function setSpinner(spinnerid, minval, maxval, initvalue) {
    $("#" + spinnerid).spinner({ min: minval, max: maxval }).val(initvalue);
}

I just added the val() at the end to set the initial value. (I also added a function name, just because you missed it in your question. Call it what you need.)

like image 98
Reinstate Monica Cellio Avatar answered Oct 21 '22 10:10

Reinstate Monica Cellio


There is no value option during spinner construction. You will have to use .val() just like @Archer suggested.
Also, another issue is increment, you mean incremental. Or step if you're trying to pass in a number. Check the linked documentation.

So your function becomes

function(spinnerId, min, max, init, step) {
    $('#' + spinnerId)
        .spinner({min:min, max:max, incremental /*or 'step'?*/:step})
        .val(init)
    ;
}

ref: spinner API

like image 45
Hashbrown Avatar answered Oct 21 '22 11:10

Hashbrown