I want to retrieve the value of selected item while it is inside a loop
to print it in javascript (alert(value)
). I can't do this document.getelementbyid
because it is inside a loop and the id will be repeated many times.
<?PHP
foreach ($res->fetchAll() as $row) {
?>
<tr>
<td>
<?php echo $row['id']; ?>
<input type="text" hidden value="<?php echo $row['id']; ?> " id="idartwork">
</td>
<td>
<?php echo $row['name']; ?>
</td>
<td>
<?php echo $row['creation_date']; ?>
</td>
<td>
<?php echo $row['artist']; ?>
</td>
<td>
<?php
if ($row['gallery'] == "") {
?>
<select id="selectname">
<option value=""></option>
<option value="ghaya gallery">ghaya gallery</option>
<option value="selma gallery">selma gallery</option>
</select>
<input type="button" value="affecter" onclick="affecter()">
<input type="text" hidden value="<?php echo $row['gallery']; ?> " id="inputgallery">
<!-- <input type="text" hidden value="--><?php //echo $row['id']; ?><!-- " id="idartwork">-->
<?php
} else {
echo $row['gallery'];
?>
<?php
}
?>
</td>
what I want to do is take the value of item select and put it in affecter() so I could print it