2

I need the variable "value" in my slider plugin to be the integer value of a input in the form:

$(function () {
  $("#calcSlider").slider({ 
    min: 0,
    max: 90,
    step: 5,
    value: /* ACCESS HERE!!!!!! */,
    slide: function (event, ui) {
      $("#calcSup").val(ui.value);
    }
  });
});

I need value: to be the value in calcSup or ${form.calcSup}, but that is a string. I need it parsed to a int:

<input type="text" 
       id="calcSup" 
       name="calcSup" 
       value="${form.calcSup}" 
       size="3" 
       readonly="readonly" />  
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Doc Holiday
  • 9,928
  • 32
  • 98
  • 151
  • possible duplicate of [How do I Convert a String into an Integer in JavaScript?](http://stackoverflow.com/questions/1133770/how-do-i-convert-a-string-into-an-integer-in-javascript). – Felix Kling May 10 '12 at 20:23

3 Answers3

2

Maybe you are looking for the parseInt function, more details can be found here:

http://www.w3schools.com/jsref/jsref_parseint.asp

$(function () {
$("#calcSlider").slider({ min: 0,
                          max: 90,
                          step: 5,
                          value: parseInt($('input#calcSup').val()),
                          slide: function (event, ui) {
                              $("#calcSup").val(ui.value);
                          }
                       });
                    });

<input type="text" id="calcSup" name="calcSup" value="${form.calcSup}" size="3" readonly="readonly"/>
Rob Angelier
  • 2,335
  • 16
  • 29
2

If you're going to parse the value to an integer, don't forget to include the radix so it doesn't wind up getting confused for base-8 or something.

$("#mySlider").slider({
  // Set initial value to that of <input type="text" id="bar" value="23" />
  value: parseInt( $("#bar").val(), 10 ),
  // Update <input type="text" id="foo" /> anytime we slide
  slide: function ( event, ui ) {
    $("#foo").val(ui.value);
  }
});

Demo: http://jsbin.com/oceqab/edit#javascript,html

Sampson
  • 265,109
  • 74
  • 539
  • 565
0

This might be what you are looking for:

$(function () {
    $("#calcSlider").slider({ min: 0,
                          max: 90,
                          step: 5,
                          value: parseInt($("#calcSup").val()),
                          slide: function (event, ui) {
                              $("#calcSup").val(ui.value);
                          }
    });
});
Josh Mein
  • 28,107
  • 15
  • 76
  • 87