I am trying to make operations(delete and edit) using javascript for each element of list. I took list from mysql database. The javascript function is returning just last value of list. enter image description here
This is php back-end
do{
echo " <li class='list-group-item note'><div><strong>".$fetch['title']."</strong>
<small>".$fetch['notedate']."</small></div>
<div>
<button type='button' class='btn btn-outline-primary' id='edit' value=".$fetch['id'].">✎</button>
<button type='button' class='btn btn-outline-danger' onClick='deleteData()' id='delete' value='".$fetch['id']."'>×</button>
</div>
</li>";
}
while ($fetch = mysqli_fetch_array($mysqli_query));
javascript:
function deleteData (){
var acc = document.getElementById("delete");
alert (acc);
}
I want javascript function return value of button individually. For exampe: if I click the buton with value=2 javascript should return 2, if 3 then 3.
do-while()loop to iterate your result set, it is probably a bad idea because it fetches the row AFTER each iteration (assuming a row exists).