We have html site based on php+mysql. On a page, there is table (4 rows and 1 column) having information about users. Each table cell has user name and appropriate button under it. User names populated to table using SELECT statement.
$q = "select usr.user_id, usr.nickname from users usr";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
Then info get’s populated into table
echo "<table border cellpadding=1>";
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){
echo "<tr>";
echo "<td>" . $row['nickname'] . "</td> <form name ='form_type' method ='GET'><input type = 'button' name = " . $row['user_id'] . " value = 'ButtonValue' id = 'ButtonId' onclick='processFormData();'></form></td>";
}
echo "</table>";
Javascript for getting ButtonName
<script type="text/javascript">
function processFormData() {
var name_element = document.getElementById('ButtonId');
alert(name_element.name);
}
Alert is using for testing.
My aim is to get user_id value upon button clicked. Currently I’m getting same user_id (firstly found) for all buttons.
Try this:
And this: