I have build a dynamic list from an array and must print the onclick event inline, I don't know of anyway other way to do this.
<?php
$dataArray = $_POST['dataArray']; // This is a valid array
ECHO '<div id="colorSelectorBox">';
for ($btn = 0; $btn < sizeof($dataArray); $btn++){
ECHO '<div class="btn-group">
<button onclick="buildGroupList("'.$dataArray.'")">' .$dataArray[$btn].'</button>
<button><div ..Stuff..></div></button>
</div><br>';
}
ECHO '</div>';
?>
The problem is that the JavaScript function buildGroupList() does not receive an array from this instead the line looks like this in my developer tool:
onclick="buildGroupList(Array)"
How can I pass in an array of values through to JavaScript?
OR
How can I re-write this so that the call is not inline?