Reputation: 39
I have these php variables:
$n= $json['health'];
$n2= $json2['health'];
The output are numbers.
Here is the jquery script:
<script>
$(function() {
var valMap = [0, 25, 50, 100, 250, 500];
$("#slider-range").slider({
min: 1,
max: valMap.length - 1,
value: 0,
slide: function(event, ui) {
$("#amount").val(valMap[ui.value]);
}
});
//$("#amount").val(valMap[ui.value]);
})
</script>
I tried to get the vars in the script as my php variables like that:
var valMap = ['<?php echo($n); echo($n2);?>';];
How can I set the variables in the right way?
Upvotes: 0
Views: 39
Reputation: 852
You should try something like that:
var valMap = [<?php echo $n.",".$n2; ?>];
Upvotes: 0
Reputation: 21
Declare an array with these variables in your PHP code.
$n_arr=array($json['health'],$json2['health']);
Then in your script use that array like this.
var valMap = <?php echo json_encode($n_arr); ?>;
This should be the tidy way to do it!
Upvotes: 0
Reputation: 4487
You should try something like that:
var valMap = [<?php echo "$n, $n2"; ?>];
Upvotes: 1