A.R A.R - 15 days ago 4
Javascript Question

onclick event alert value of variable php mysql

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>

Answer

pass the parametre in your function

function blockit(val)
{
  alert(val);
}