How to create a confirmation window on a PHP system?

Asked

Viewed 1,203 times

0

I am a beginner in programming and I am creating a small system and in it I will have a button to release the user, the code:

<a href="../controller/controller.deslogar.php" title="Deslogar"><img src="img/logout.png" class="icon2"></a>

As you may have noticed, when clicking on the image, the user is automatically dropped, but I would like to put a confirmation window before releasing the user, because sometimes he may have accidentally clicked. I would like the confirmation window to have 2 buttons, "OK" and "Cancel", if the user clicked on the "OK" button, it would be dropped, if he clicked on "Cancel", just close the confirmation window.

I looked on the internet, but I did not find exactly what I wanted and as I am beginner, I can not create from 0 this.

Thank you!

2 answers

1

I wonder if this is what he wants?

<a href="../controller/controller.deslogar.php" onclick="return confirm(Quer deslogar?');" title="Deslogar"><img src="img/logout.png" class="icon2"></a>

It can also be done as follows:

var logout = confirm("Quer fazer logout?");

if(logout){
     location.href = "../controller/controller.deslogar.php";
}
  • Exactly that! The only problem is when I give F5 already appears the confirmation window, it should appear only when I click on the button.

  • @Gabrielqueiroz Appears because F5 alone does not update Javascript, you will need to crtl + F5 to update full page

0

Try with Jquery:

$('a[title="Deslogar"]').click(function(){
    confirm('Quer fazer logout?');
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.