I have 2 arrays, 1 with indexes and colors in hexadecimal (without #) another one with corresponding indexes and type of exercise.
What I'm trying to achieve by that is generating a schedule, which to a div containing specified exercise type adds a class "ExerciseType" + index of exercise from an array. It's like this e.g. "ExerciseType0" or "ExerciseType1" (got that one done and working). Then I'm trying to use jQuery to change background colors to the div's with classes corresponding to indexes.
To do that I've tried to write a function $ColorIndex - array of indexes as key's and colors in hexadecimal as value's .ExerciseType0 etc. got no styling before.
<script type=\"text/javascript\" src=\"jquery-1.8.2.js\"></script>
<script type=\"text/javascript\">
$(document).ready(function(){
var ColorIndexJS = <?php echo json_encode($ColorIndex) ?>;
var ColorIndexLength = ColorIndexJS.length;
var counter = 0;
while(counter<ColorIndexLength){
$('.ExerciseType' + counter.toString()).css("background-color", "#"+ColorIndexJS[counter]);
counter++;
}
});
</script>
The result I get from this code in firebug is
$(document).ready(function(){
var ColorIndexJS = ["FF4040","EEC591","FF7F24"];
var ColorIndexLength = ColorIndexJS.length;
document.write("ExerciseType");
var counter = 0;
while(counter<ColorIndexLength){
$('.ExerciseType' + counter.toString()).css("background-color", "#"+ColorIndexJS[counter]);
counter++;
}
});
As seen here php_array is converted successfully, but the function itself just doesnt want to work. Any ideas?