I'm new in Jquery and have to display multiple JQuery sliders in one page.
I have to display a slider every time a result comes from a MySQL requests.
I can display one slider, but can't display multiple sliders, because I can't change the name of the ID in javascript.
I'm also not able to call this function multiple times... Please help.
HTML page:
<?php
$reponse = $bdd->prepare('SELECT id FROM TABLE WHERE deleted = 0 ');
$reponse->execute();
$slider = array();
$i = 0;
while ($data = $reponse->fetch()) {
$slider[$i] = $data['id'];
$i ++; ?>
<div id="<?php echo "slider" . $data['id']; ?>"> </div>
<input type="text" id="<?php echo "amount" . $data['id']; ?>"> <?php
} ?>
Javascript page:
$(function() {
var name = "#slider1";
$( name ).slider({
value:100,
min: 5,
max: 300,
step: 5,
slide: function( event, ui ) {
$( "#amount" ).val( ui.value);
}
});
$( "#amount" ).val( $( name ).slider( "value" ));
});
//EDIT
Slider is joined with class to all elements, but I can't put the right value of the slidebar into amount.
I have several options to take the ID of current slider moving, but none of them work:
$(function() {
$( ".slider" ).slider({
value:100,
min: 5,
max: 300,
step: 5,
slide: function( event, ui ) {
// check the event and ui variables to see what the exact reference you
// your element is but it looks like it's ui.handle
// console.log(ui);
// console.log(ui.handle);
var clicked_element = ui.handle.data('id');
$( "#amount" + clicked_element ).val( ui.value);
}
});
$( "#amount3" ).val( $( ".slider" ).slider( "value" ));
});
ui.handle.data('id')give you? Note that the last line of your code will not work, you need to loop over all.sliderelements and put the correct value in the correct#amountbox.undefined is not a function, that's the only thing I can see. I know about the last line. Looping works, but trying to get the last ID in this loopconsole.log(ui.handle);? Do you have a test-page online?<span class="ui-slider-handle ui-state-default ui-corner-all" tabindex="0" style="left: 33.8983050847458%;"></span>