How to disable slide range when checked checkbox? - javascript

How to disable slide range when checked checkbox ?
When checked checkbox id="unlimited" I want to disable slide range
$( "#amount" ).val( "$" + $( "#slider-range-min" ).slider( "disable" ) );
but when not checked checkbox id="unlimited" i want enable slide range
$( "#amount" ).val( "$" + $( "#slider-range-min" ).slider( "value" ) );
I test this code but not work, How can i do that ?
FIND FIDDLE HERE
SCRIPT
$(function() {
$( "#slider-range-min" ).slider({
range: "min",
value: 0,
min: 0,
max: 700,
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.value );
}
});
if (document.getElementById('unlimited').checked)
{
$( "#amount" ).val( "$" + $( "#slider-range-min" ).slider( "disable" ) );
}
else
{
$( "#amount" ).val( "$" + $( "#slider-range-min" ).slider( "value" ) );
}
});

To disable JqueryUi Slider, you should use option disabled property to set it. Also you need to grab the event of check box to set the slider disable and enable ability.
Just put the bellow code, this will set property as your expected behavior. You can see this in http://jsfiddle.net/b63u9krv/10/ and also like bellow:
$(function() {
$("#slider-range-min" ).slider({
range: "min",
value: 0,
min: 0,
max: 700,
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.value );
}
});
// Grab the click event of check box.
$( "#unlimited" ).click(function(){
if(this.checked)
{
// set the slider as disable
$( "#slider-range-min" ).slider( "option", "disabled", true );
}
else
{
// set the slider as enable again when you click to uncheck
$( "#slider-range-min" ).slider( "option", "disabled", false );
}
});
});

Related

Javascript Paypal slider string suffix

I have this code http://jsfiddle.net/y8owze31/6/. I need to be able to apply a suffix to the string via a variable. The way I am doing it now is very primitive. What I mean is
$(function() {
var1 = "suffix"
$( "#slider-range-max" ).slider({
range: "max",
min: 1,
max: 50,
value: 25,
slide: function( event,ui, string) {
$( "#amount" ).val( ui.value + "suffix" );
$( "#amt_id" ).val( ui.value );
}
});
$( "#amount" ).val( $( "#slider-range-max" ).slider( "value" ) );
});
But this doesn't seem to work the way I would like it to and just tries to calculate with the string.
In you situation, you need to define your value type in:
$( "#amount" ).val( ui.value + "suffix" );
and in:
$( "#amount" ).val( $( "#slider-range-max" ).slider( "value" ) );
javascript does not know which type of data you enter. You should define such as respectively:
$( "#amount" ).val( "" + ui.value + "suffix" );
and
$( "#amount" ).val("" + $( "#slider-range-max" ).slider( "value" ) + "suffix" );
See, you add some quotation mark in where your value is you simply edit your variable as a string value.
Cheers!
And here is JSFiddle example

jQuery Slider Min Value

I know there is a min value in jquery's slider. However, is there a way I can make the slider handle stop moving under some value? Is there any variable I can change to make this happen?
Note: My Slider is vertical
Basically, if the minimum is 20, I don't want the slider handle going under 20.
Well you can check it in slide functionality as below:
DEMO HERE
$(function() {
$( "#slider-range" ).slider({
orientation: "vertical",
range: false,
value:20,
slide: function( event, ui ) {
if (ui.value < 20) // corrected
return false;
else
$( "#amount" ).val( ui.value );
}
});
$( "#amount" ).val( $( "#slider-range" ).slider( "value" ) );
});

Adding dynamic elements

I am using the code bellow to use the Jquery UI Slider.
<script>
$(function() {
$( "#slider" ).slider({
value:100,
min: 0,
max: 500,
step: 50,
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.value );
}
});
$( "#amount" ).val( "$" + $( "#slider" ).slider( "value" ) );
});
</script>
How can add multiple sliders with a button? I want to add slider elements when I click the button bellow.
<div id="adding"></div>
And how can I control them? This single slider has a jQuery code to work...
$("#adding").click(function() {
$("<div>").slider({
// options
}).appendTo("#sliderContainer");
});

detect textbox change when the jquery UI slider moves

I have this fiddle http://jsfiddle.net/48Hpa/ , it calculates the sum automatically when I enter the keyword by myself, when I change the slider, the textbox value changes, but I don't see the sum. Why is this? How can I make this work? Thank you very much.
$(document).ready(function(){
$(function() {
$( "#slider1" ).slider({
range: "min",
value: 36,
min: 1,
max: 36,
slide: function( event, ui ) {
$( ".amount1" ).val( ui.value);
}
});
$( ".amount1" ).val($( "#slider1" ).slider( "value" ));
});
$(function() {
$( "#slider2" ).slider({
range: "min",
value: 50000,
min: 1,
max: 50000,
slide: function( event, ui ) {
$( ".amount2" ).val( ui.value );
}
});
$( ".amount2" ).val( $( "#slider2" ).slider( "value" ));
});
function writesum() {
var months = $('.amount1').val();
var credits = $('.amount2').val();
var payment = Number(months) + Number(credits);
$('.amount3').val(payment);
}
$(".amount1").on('input',function(){
jQuery(writesum);
});
$(".amount2").on('input',function(){
jQuery(writesum);
});
});
How about just calling writesum() whenever the slider moves?
i.e. http://jsfiddle.net/48Hpa/1/
You need to trigger a change event on the input fields when you change their value with code.
Also, I suggest using the change event.
$( "#slider1" ).slider({
...
slide: function( event, ui ) {
$( ".amount1" ).val( ui.value)
.trigger('change');
}
});
$( "#slider2" ).slider({
...
slide: function( event, ui ) {
$( ".amount2" ).val( ui.value )
.trigger('change');
}
...
$(".amount1, .amount2").on('change', function() {
writesum();
});

jQuery: (this) ui.value solution

I'm pretty new to jquery, but this is question. From my code below I have made 3 sliders each within a tag. Each of the three has an input field that is changed when the slider is moved to show the current value of the slider (simple jQueryUI plugin sliders). The final line involves another plugin that links all the sliders together so that they all add to 100 total and move when the others move.
The problem I'm having is that when I slide one, its value changes and shows but the others do not. I can get all of the values to change with some extra lines of code, but I don't know how to get (this) ui.value so that I can display the separate values for each of the sliders.
You can see in the third slider I tried to get it to do that, but the way it is set it only takes the same ui.value of the current slider being moved.
Can anyone help me with a solution to get (this) ui.value of the other sliders when i need to change it?
($(function() {
$( "#RedSlider" ).slider({
orientation: "horizontal",
range: "min",
min: 0,
max: 100,
value: 1,
animate: true,
slide: function( event, ui ) {
$( "#RedValue" ).val( ui.value );}
});
$( "#RedValue" ).val( $( "#RedSlider" ).slider( "value" ) );
});
$(function() {
$( "#BlueSlider" ).slider({
orientation: "horizontal",
range: "min",
min: 0,
max: 100,
value: 1,
animate: true,
slide: function( event, ui ) {
$( "#BlueValue" ).val( ui.value );}
});
$( "#BlueValue" ).val( $( "#BlueSlider" ).slider( "value" ) );
});
$(function()
{
$( "#EmptySlider" ).slider({
orientation: "horizontal",
range: "min",
min: 0,
max: 100,
value: 98,
animate: true,
slide: function( event, ui )
{
$( "#EmptyValue" ).val( ui.value );
$( "#RedValue").val(ui.value);
$( "#BlueValue").val(ui.value);
}
});
$( "#EmptyValue" ).val( $( "#EmptySlider" ).slider( "value" ) );
$( "#RedValue").val($("RedSlider)").slider("value"));
$( "#BlueValue").val($("RedSlider)").slider("value"));
});*/
$('div:gt(2)').slider().linkedSliders({policy: 'last'});
Your code will only every be executed once. You need to change the following line:
$( "#BlueValue" ).val( $( "#BlueSlider" ).slider( "value" ) );
To be something different when selecting the value of your slider at whatever time you need it.
This code:
$( "#BlueValue" ).val( $( "#BlueSlider" ).slider( "value" ) );
will only execute once. You need to have that in a value-changed callback for the slider, so the value will be updated continually.

Categories