最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Sending value from ui.value (jquery UI) of a slider to #link - Stack Overflow

programmeradmin0浏览0评论

im a jq newbie, but im fighting my way trough ;(

question:

i need to pass a slider variable(ui.value) to a "http://NAME/sensor?ConnectFloat InputB cf_GrA_l2pY VALUE_FROM_SLIDER" where value_from_Slider is the value, when i stop sliding. .

my code can be found here: /

or here:

 $(function() {
    $("#slider").slider({                   
            value: 50,
            min: 0,
            max: 99,
            step: 1,
            slide: function(event, ui) {
                    $("#slider_value").val(ui.value);
                      }
    });
    $("#slider_value").val($("#slider").slider("value"));


});  

html:

<div id="slider"></div>    
sliderValue:

i know that im missing a new $function, but this is as far as i understand.

Thanks for any help!

im a jq newbie, but im fighting my way trough ;(

question:

i need to pass a slider variable(ui.value) to a "http://NAME/sensor?ConnectFloat InputB cf_GrA_l2pY VALUE_FROM_SLIDER" where value_from_Slider is the value, when i stop sliding. .

my code can be found here: http://jsfiddle/f2AWC/30/

or here:

 $(function() {
    $("#slider").slider({                   
            value: 50,
            min: 0,
            max: 99,
            step: 1,
            slide: function(event, ui) {
                    $("#slider_value").val(ui.value);
                      }
    });
    $("#slider_value").val($("#slider").slider("value"));


});  

html:

<div id="slider"></div>    
sliderValue:

i know that im missing a new $function, but this is as far as i understand.

Thanks for any help!

Share Improve this question edited Oct 6, 2011 at 8:09 Reporter 3,9485 gold badges35 silver badges49 bronze badges asked Oct 6, 2011 at 8:04 DesmondDesmond 211 silver badge5 bronze badges 2
  • I'm not sure wha tyou looking for are you trying to setup the slider based on the value of "NAME/sensor?ConnectFloat InputB cf_GrA_l2pY VALUE_FROM_SLIDER" where value_from_Slider is the value. Or are you wanting to make a url and place the value for the slider in the url. Please could you explain a bit more to make it clear what you wanting to do. – Alistair Laing Commented Oct 6, 2011 at 8:20
  • i want to put the slider value in the href link and trigger it when user stop sliding, so the other side updates accordigly. – Desmond Commented Oct 6, 2011 at 9:07
Add a ment  | 

4 Answers 4

Reset to default 5

use the stop event

$sliderValue="";
$("#slider").slider({                   
                value: 50,
                min: 0,
                max: 99,
                step: 1,
                slide: function(event, ui) {
                                $("#slider_value").val(ui.value);
                          },
            stop: function(event, ui) {
            alert(ui.value);
                $sliderValue=ui.value; //set the value to a global variable
            }
        });
        $("#slider_value").val($("#slider").slider("value"))

//send the value here
// $.post("http://NAME/sensor?ConnectFloat InputB cf_GrA_l2pY VALUE_FROM_SLIDER",{value:$sliderValue},function(data){...});

here is the fiddle http://jsfiddle/f2AWC/34/

I am not sure I understand the part with http://NAME/sensor?ConnectFloat InputB cf_GrA_l2pY VALUE_FROM_SLIDER. Can you elaborate a bit more there?

When you stop sliding, you can use stop function, which works the same way as slide. Documentation here

you can use the slider val and append it to the link href

e.g.

$('#link').attr('href','http://NAME/sensor?ConnectFloat InputB cf_GrA_l2pY '+$("#slider_value").val());

Demo - http://jsfiddle/Jayendra/f2AWC/32/

It might be a bit late to answer on the post. But after looking at the question.You might need to send an AJAX request over the stop event of the jquery slider.

Following code might be helpful in future for fellow programmers facing the same problem.

$(document).ready(function(){
$("#slider").slider({
            range : "min",
            min : 0,
            max : 100,
            value : 3,
            stop : function(event, ui) {                     
                slideValue = ui.value;
                       $.ajax({
                     url : "http://sample/url/request",
                    type : "POST",
                    data : {
                        "slideValue" : slideValue
                    },
                                dataType : "json",
                         success : function(response){
                                         console.log(response);
                    }
                });
            }
        });
});

http://api.jqueryui./slider/#toptions

发布评论

评论列表(0)

  1. 暂无评论