A.R A.R - 8 months ago 85
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));
<button type="button" class="btn btn-danger" id="block" onclick="blockit(this.value);" value="<?php echo $row['id'];?>">Block</button>


function blockit()
var a=document.getElementById("block").value;

Answer Source

pass the parametre in your function

function blockit(val)