开发者

jQuery slider value save

开发者 https://www.devze.com 2023-02-05 03:56 出处:网络
I have an input and jQuery slider next to it. <div id=\"slider_value_1\" class=\"slider\"></div> <input type=\"text\" name=\"value_1\" value=\"<?php echo get_option(\'value_1\'); ?&

I have an input and jQuery slider next to it.

<div id="slider_value_1" class="slider"></div> <input type="text" name="value_1" value="<?php echo get_option('value_1'); ?>" />  

The slider settings are:

 $(".slider").slider({
        sl开发者_Python百科ide: function(event, ui) {
            $(this).next().val(ui.value);
        }
    });

 $("#slider_value_1").slider({ min: 1, max: 2000, step: 100  });   

So when I move the slider to the very right - it shows 2000 in the input next to it and when I move the slider to the left - it shows 1.

The problem is I'm saving my form and it saves input's value perfectly but I want to save slider's position also? How to do that?

I guess:

<div id="slider_value_1" class="slider" value="<?php echo get_option('value_1'); ?>"></div>  

Won't work?


Given that your input has the correct value, perhaps you can put something like the following in your slider init

$("#slider_value_1").slider({ min: 1, max: 2000, step: 100, value: $("input[name='value_1']").val() }); 


I have done this with php, mysql, and jquery.

This is with a slider going from 0 to 100, 50 being the middle.

  1. In your input field grab the saved value from the database if it exist, if not set the slider to 50: <input type="hidden" name="input1" id="input1" value="<php $x = $row_y['value']; if($x == null){echo '50';} else{echo $x;}>"

  2. Add a variable in javascript that takes the value from input field and then updates the field value:

    var z= $(input).val(); $( ".slider" ).slider({animate: true,range: "min",value: z,min: 10,max: 100,step:10,change: function(event, ui) { $('#input1').attr('value', ui.value);} });

  3. Then you can submit the form to update the value.

Hope this helps.


jQuery slider value save*dynamic value in multiple slider in for loop how to resolve this i have post my script please improve my answer*

var vote_position = $("#hidden").val(); //var value_slider_dynamic = parseInt(vote_position); var value_slider_dynamic = parseInt($("input[name='value_dynamicslider']").val());

            //alert(vote_position);
        //var vote_position = $(this).attr('datamin');
        //$(selector).attr('datamin');
        //alert(vote_position);
        //$(".slider").slider('option', vote_position);

            $(".slider").slider({
            /*isRTL: true,
            isLTR: true,*/
            /*range: "min",*/

            range: "min",
            step: 1,
            min: 1,
            max: 3,
            value: value_slider_dynamic,
0

精彩评论

暂无评论...
验证码 换一张
取 消