i tried getting the button id, setting it as a variable and set it as inner element of a paragraph tag. but it is failing, im not sure where i messed up the process.
here is what i have done so far.
dont worry about the innerhtml being wrong, it works when i replace it with string texts. i just removed the rest so its clearer
let me know if im missing some key information. ill edit it right away
<script>
function ViewDetail(clicked_id) {
let btnid = obj.id;
document.getElementById("outme").innerHTML = btnid;
}
</script>
<a href="view.php?id=<?=$rows['id']?>" class="btn btn-primary" onclick="ViewDetail(this.id)" data-toggle="modal" data-target="#myModal">View</a>
<div class="modal-body">
<p id='outme'>default id</p>
</div>
CodePudding user response:
Have added Id attributes in button:
<script>
function ViewDetail(btnid) {
let btnid = obj.id;
document.getElementById("outme").innerHTML = btnid;
}
</script>
Added Id attributes:
<a id="<?=$rows['id']?>" href="view.php?id=<?=$rows['id']?>" class="btn btn-primary" onclick="ViewDetail(this.id)" data-toggle="modal" data-target="#myModal">View</a>
<div class="modal-body">
<p id='outme'>default id</p>
</div>