Reputation: 23
So I have a forms on a html page which retrieve data from a mysql table. The user can modify these data, or delete the entire row. I have a html button with functionality of deleting the entire row, and with that button I have a javascript function that displays a confirm pop up box confirming if the user wants to delete it. If they click yes then it is sent to another php page where the deletion is performed. The problem is when I click on the confirm box nothing happens, it just stays on the same page. Here is my html and javascript code:
<form class="form-inline" method=GET action="envoieModifierAlbumAdmin.php">
<table class="table table-striped">
<tr>
<td><button type="button" class="btn btn-danger" onclick="verif()">Supprimer Cet Album</button>
</td><td></td><td></td>
</tr>
<tr>
<td><label for="exampleInputName2">id: </label>
<input readonly type="text" class="form-control" value="<?php echo "$donnees[id]"?>" id="exampleInputName2" name="id">
</td><td></td><td></td>
</tr>
<tr>
<td><label for="exampleInputName2">Nom d'album: </label>
<input type="text" class="form-control" id="exampleInputName2" name="titre" value="<?php echo "$donnees[titre]"?>"></td>
<td></td><td></td>
</tr>
</table>
</form>
<script>
function verif(){
var x;
if(confirm("Vous êtes sûr que vous voulez supprimer ce compte?") == true){
document.location="supprimerAlbumAdmin.php?id=$_GET['id']";
}
else
}
</script>
The only problem is with the button, the other parts of the table above are just to show an example of what the user is modifying. Thanks in advance!
Upvotes: 0
Views: 97
Reputation: 12085
your value should be like this
value="<?php echo $_GET['id'] ?>"
not like this
value="<?php echo "$donnees[id]"?>"
and change button type into submit
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
function verif(){
alert("hi");
var x;
if(confirm("Vous êtes sûr que vous voulez supprimer ce compte?") == true){
//window.location.replace("https://google.com");
//exit();
return true;
}
else
{
return false;
}
}
</script>
<form class="form-inline" method="GET" action="envoieModifierAlbumAdmin.php">
<table class="table table-striped">
<tr>
<td><label for="exampleInputName2">id: </label>
<input readonly type="text" class="form-control" value="" id="exampleInputName2" name="id">
</td><td></td><td></td>
</tr>
<tr>
<td><label for="exampleInputName2">Nom d'album: </label>
<input type="text" class="form-control" id="exampleInputName2" name="titre" value=""></td>
<td></td><td></td>
</tr>
<tr>
<td><button type="submit" class="btn btn-danger" onclick="verif()">Supprimer Cet Album</button>
</td><td></td><td></td>
</tr>
</table>
</form>
Upvotes: 1
Reputation: 327
Try following:
function verif(){
var x;
if(confirm("Vous êtes sûr que vous voulez supprimer ce compte?")){
window.location.href="supprimerAlbumAdmin.php?id=<?php echo $_GET['id']; ?>";
}
}
Upvotes: 0
Reputation: 8101
Try
function verif(){
var x;
if(confirm("Vous êtes sûr que vous voulez supprimer ce compte?") == true){
window.location.href="supprimerAlbumAdmin.php?id=<?php echo $_GET['id']; ?>";
}
else
}
Upvotes: 0