I have a Javascript function which changes the background color of a DIV ID. I just send it the DIV ID and the Color. changeBG(DivID, Color)
I would like the Div ID to be a variable, so I can set the variable and then call the function. It works fine if I hard code the literal string of the Div ID - 'floorData2" in the example below. I have a PHP variable ($floorDiv) which contains the Div ID and would like to replace 'floorData2' with $floorDiv in the call to the changeBG() function.
I have tried single quotes, double quotes, escaped quotes in every combination I can think of. I still can't make it work. What is the correct syntax to use the variable $floorDiv?
<?php
$floorCount =5;
$floorNow = 1;
while ( $floorNow <= $floorCount) {
$floorDiv = 'floorData1'; /* this will change based on floorNow */
echo '<div class="FloorH">
First Floor <button onclick="changeBG(\'floorData2\',\'#F0F\');">Magenta</button>
</div>';
echo "<div id='floorData$floorNow'>";
echo "</div>";
$floorNow = $floorNow + 1;
}
?>