I want to call a javascript function myfunction() from php code. the code is as follows:
<script>
function myfunction() {
var r = confirm("Are you sure ? ");
if (r == true) {
//delete file from database with id b_id
}
<?php header("Refresh:0"); ?>
}
</script>
I want to call the js function from this php code.
<?php
while(//fetched database elements one by one)
{
//$b_id fetched from database.
echo "<button class='w3-display-topright pe-7s-close-circle w3-xxlarge w3-button' onclick="myfunction($b_id);"></button>
}
?>
Write another PHP script that deletes an entry by ID and call it from your web page. I.e.,
<?
while (...) {
echo "<button onclick='deleteEntry($id)'></button>"
}
?>
With your JS being something like this:
function deleteEntry(id) {
if (confirm('Are you sure?')) {
fetch('myserver/delete_entry.php?id=' + id);
}
}
You have to write delete_entry.php
, of course.