I have a playlist produced dynamically by a user from an sql database. I want to change the colour of the background from a button with onclick(). The idea of the div comes from the song name as a variable from sql. I have used the variable in the javascript and in the html div. Each time I click the button it is only the last name that is changed. I’m very much a newbie (62 yr old home coder) but trying to learn. Here is the code from the website: 2 records
<form>
<table>
<tr>
<td>
<div id="angelscall">angelscall</div>
</td>
<td>
<button id="allchange" type="button" onclick="changecolor()">Change Colour</button>
</tr>
</table>
<script>
function changecolor() {
document.getElementById("angelscall").style.backgroundColor = "green";
}
</script>
<table>
<tr>
<td>
<div id="merkabah">merkabah</div>
</td>
<td>
<button id="allchange" type="button" onclick="changecolor()">Change Colour</button>
</tr>
</table>
<script>
function changecolor() {
document.getElementById("merkabah").style.backgroundColor = "green";
}
</script>
</form>
Here is my html/javascript coding: I use the php include so that all the ids and javascript are in the same place
<?php $track = strtolower(str_replace(' ', '', $row['wcpmusic']));?>
<?php echo $track;?>
| Change Colour |
This is the html where the above script is called testtrack.php :
<?php $etitle= $row['etitle'];?> <?php $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); $query = "SELECT * FROM workshopcontrolpanel WHERE wcpevent = '$_POST[bevent]' ORDER BY wcpmusic ASC "; $result = mysqli_query($dbc, $query) or die('Error querying first database.'); while ($row = mysqli_fetch_array($result)) { ?> <?php include("testtrack.php"); ?> <?php } mysqli_close($dbc); ?>I hope this makes sense. I tried to ask this question on stack overflow but all I got was criticism about how I code and not asking correctly! I’m hoping this place is a little more friendly.
Regards
Andrew