Pass jQuery slider variables through to Laravel controller - javascript

Currently, I am using the jQuery slider with range. What I want to do is, upon the user submitting the form, I want the two values (max and min) to also be sent over to the controller, so I can save them in the database. They are both currently saved in the variable values:
$(function() {
$( "#slider-range" ).slider({
range: true,
min: 0,
max: 1000000,
step: 10000,
values: [100000 , 300000 ],
slide: function( event, ui ) {
$( "#amount" ).val( "£" + ui.values[ 0 ] + " - £" + ui.values[ 1 ] );
},
stop: function(event, ui) {
var values = $( "#slider-range" ).slider( "values" );
}
});
$( "#amount" ).val( "£" + $( "#slider-range" ).slider( "values", 0 ) +
" - £" + $( "#slider-range" ).slider( "values", 1 ) );
});
I have alerted the variable and it echos the correct two variables. I am at a complete loss as to how to get the two variables, possibly split, over to my Laravel controller, once the user submits the form.
I usually get the form's variables through the Input::get method:
$id = Input::get('id');
But trying to access this variable always returns NULL
Any help would be hugely appreciated.

Here is a jsfiddle of how to get it working properly. My guess is that you forgot to set the "name" attribute on the HTML input field.

Related

retrieve jquery slider value in js

i have a jquery slider function and other javascript functions
i would like to retrieve the value of the jquery slider in javascript but i cant
if i do this
var s=$( "#slider_placement" ).slider( "value" );
in javascript it says error
Error: cannot call methods on slider prior to initialization; attempted to call method 'value'
i tried doing this in java script
var h = $('#custom-handle').text();
console.log(h);
but the console shows me empty result
here is the jquery slider code
$( function() {
var handle = $( "#custom-handle_wins" );
$( "#slider_wins" ).slider({
min:1,
max:10,
value:1,
step:1,
create: function() {
handle.text( $( this ).slider( "value" ) );
},
slide: function( event, ui ) {
handle.text( ui.value );
var s=ui.value;
document.getElementById("no_wins").innerHTML='Number of Wins: ' + ui.value;
}
});
s=$( "#slider_wins" ).slider( "value" );
document.getElementById("no_wins").innerHTML='Number of Wins: ' + s;
} );

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

How to fetch values from specific elements which are dynamically created in JavaScript

I am new to Javascript and Jquery.
I started making changes in business rules by Chris Powers. https://github.com/chrisjpowers/business-rules
I want to add a range slider in numbers and want to add a number spinner also. I have tried using open source sliders.
But the problem I faced is if I place the slider's html in plain html file then it is rendering. But since we want it dynamically generated therefore trying through javascript is not giving the required results, it just shows a blank text field.
Example: (from jquery-UI)
<div class="slider-range"></div>//this works
But if tried from javascript like:
var input = $("<div>",{"class":" slider-range rem "});
$this.after(input);
this creates a blank input text box.
I thought that the supporting javascript is not read when inside another file hence I wrote in my header like:
<script>
$(function() {
$( ".slider-range" ).slider({
range: true,
min: 0,
max: 100,
values: [ 75, 100 ],
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
}
});
$( "#amount" ).val( "$" + $( ".slider-range" ).slider( "values", 0 ) +
" - $" + $( ".slider-range" ).slider( "values", 1 ) );
});
</script>
it still doesn't seem to work.
I apologize for my ignorance but I have tried hard to get it working. Please give me some hope.
I created a DEMO FIDDLE It seems to be working fine.
var input = $("<div>",{"class":" slider-range rem"});
$("#empty").after(input);
$( ".slider-range" ).slider({
range: true,
min: 0,
max: 100,
values: [ 75, 100 ],
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
}
});
$( "#amount" ).val( "$" + $( ".slider-range" ).slider( "values", 0 ) + " - $" + $( ".slider-range" ).slider( "values", 1 ) );

Javascript/PHP How to save slider value once form submitted?

I have a form with random filters and a slider that adjusts the width/height of items.
How can I save the slider value once the form is submitted so that when I go back to the slider, I see the value I left it on?
My attempt:
<input type="text" id="amount" name="slider_id" value="<?php if (isset($_POST['slider_id'])){ echo $_POST['slider_id']; }?>">
<div id="slider"></div>
The Javascript:
$(function() {
$( "#slider" ).slider({
value:$("input[name='slider_id']").val(), min: 80, max: 400, step: 10,
slide: function( event, ui ) {
$( "#amount" ).val( ui.value-70 + "%" );
$('.display').css('width', ui.value + 'px');
}
});
$( "#amount" ).val( $( "#slider" ).slider( "value" ) + "%" );
});
Right now it will show NaN after the form is submitted. All help is much appreciated!
Looks to me that the problem is in php value set.
Just modify the value of the input before calling the slider.
$(function () {
var newVal = $('input').val().replace("%","");
$('input').val(newVal);
$("#slider").slider({
value: $("input[name='slider_id']").val(),
min: 80,
max: 400,
step: 10,
slide: function (event, ui) {
$("#amount").val(ui.value - 70 + "%");
$('.display').css('width', ui.value + 'px');
}
});
$("#amount").val($("#slider").slider("value") + "%");
});
http://jsfiddle.net/joeSaad/hZCDZ/#base
Your problem is here: $("input[name='slider_id']").val()
Debug it and you'll find that it's some form of "nn%", thus, a string.
$.slider requires that value be numeric.
You need to parse it somehow:
value: parseInt($("input[name='slider_id']").val().replace('%', ''), 10)

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