I'm trying to print a value from several buttons. The value and ID of the buttons are defines in my table. This works fine with only one element in the table, but not with several. I guess I need to loop it somehow. Any suggestions? (PS. Does not have to be a button)
<?php
$sql_rel = "SELECT * FROM TABLE";
$result1 = mssql_query($sql_rel);
$count = mssql_num_rows($result1);
while ($row1 = mssql_fetch_assoc($result1)){
echo '<button id="' . $row1['NAME'] . '" onClick="func()" value="'.$row1['NAME'].'">'.$row1['DESCRIPTION'].'</button>';
}
<p id="print"></p>
<script>
function func(){
var x = document.getElementById("<?php
$sql_rel = "SELECT * FROM TABLE";
$result1 = mssql_query($sql_rel);
$count = mssql_num_rows($result1);
while ($row1 = mssql_fetch_assoc($result1)){
echo $row1['NAME'];
}
?>").value;
document.getElementById("print").innerHTML = x;
}
</script>