how to get the value selected in this jquery slider [closed]
here is the code
<script>
$( ".slider" ).slider({
animate: true,
range: "min",
value: 0,
开发者_运维百科 min: 0,
max: 4,
step: 1,
//this gets a live reading of the value and prints it on the page
slide: function( event, ui ) {
if(ui.value ==0)
$( "#slider-result" ).html( "Poor");
else if(ui.value == 1)
$( "#slider-result" ).html( "Average");
else if(ui.value == 2)
$( "#slider-result" ).html( "Good");
else if(ui.value == 3)
$( "#slider-result" ).html( " Very Good");
else if(ui.value == 4)
$( "#slider-result" ).html( "Excellent");
},
//this updates the hidden form field so we can submit the data using a form
change: function(event, ui) {
$('#hidden').attr('value', ui.value);
}
});
</script>
this slider create a jquery slider and display "excellent verygood good poor" and so on. on selecting . now i need to get the value of slider selected how to do that????
Your code is setting the value
of an element with id
"hidden" when the slider changes. See the line:
$('#hidden').attr('value', ui.value);
You should therefore be able to get the current value of the slider by getting the value of that element:
var currentValue = $('#hidden').val();
However, the hidden input with id
"hidden" does not have an initial value, so this won't work if the slider has not yet changed. You can fix that by giving a value to that hidden input element.
I am assuming the entire reason you have it updating a hidden input element on change is so you can access that value at some point...
slider value is stored in the... value: $(".slider").slider.value
精彩评论