Reputation: 85
I need to use the variable $currentSliderCount
, which holds the current slider value
in the second statement of my for loop, instead of $chCount
I want to pass $currentSliderCount
how to accomplish this?
I use the jquery ui slider.
// filename = slider.blade.php
$currentSliderCount = $('#number_of_chapters').val();
for(var i = 0; i < $currentSliderCount; i++) {
// php loop blade syntax
}
@for ($i = 0; $i < $chCount; $i++)
$('#sliderAppendNumCh').append('...');
@endfor
I tried it with ajax like this:
change : function(e, slider) {
$.ajax({
type: "POST",
url: "/",
data: slider.value,
success: function() {
// add chapters
$('#sliderAppendNumCh').empty();
for(var i = 0; i < $currentSliderCount; i++) {
}
@for ($i = 0; $i < $chCount; $i++)
$('#sliderAppendNumCh').append('...');
@endfor
}
}
});
},
But I do not know how I can use that value from ajax.
Upvotes: 0
Views: 815
Reputation: 1654
Web development is all about communication. In this case, communication between two (2) parties, over the HTTP protocol:
Each side's programming, refers to code which runs at the specific machine, the server's or the client's.
So the code on your server(PHP) doesn't know about your variable on the client side.
As far as i can see you can solve your problem with just using Javascript as followed:
for(var i = 0; i < $currentSliderCount; i++) {
for (var d = 0; d < $currentSliderCount; d++)
{
$('#sliderAppendNumCh').append('...');
}
}
Tell us about the bigger picture if this solution doesn't work for you.
You could try passing the PHP variable to Javascript like so:
var chCount = <?php echo $chCount;?> ;
First you need to create a new laravel route which returns the ChCount variable. Then do a ajax post and execute code on success like so:
change : function(e, slider) {
$.ajax({
type: "POST",
url: "/getChCount",
data: slider.value,
success: function(data) {
// add chapters
$('#sliderAppendNumCh').empty();
for(var i = 0; i < $currentSliderCount; i++) {
for (var d = 0; d < data; d++){
$('#sliderAppendNumCh').append('...');
}
}
}
}
});
},
Upvotes: 1