I want to alert id when user click on the button.But i am getting the same id on every button whereas when i inspect element it have different values. This is a part of my code
Fetching code:
$sql="select * from `table_name`";
$result=mysqli_query($con,$sql) or die(mysqli_error($con));
while($row=mysqli_fetch_array($result))
{
<button type="button" class="btn btn-danger" id="block" onclick="blockit(this.value);" value="<?php echo $row['id'];?>">Block</button>
Query:
<script>
function blockit()
{
var a=document.getElementById("block").value;
alert(a);
}
</script>
blockit-function you provided does not take any arguments...buttons with sameidblockit(this.value)then useblockit(value)andalert(value)... simpleclassinstead ofidas you may have many buttons