onclick "confirm" does not work Cancel button

Asked

Viewed 318 times

0

I have an onclick confirm in my code that, if ok, it sends a variable to a specific page. If Cancel... it should cancel the operation.

But even if you click on Cello, it is sending the variable to the page.

Follows the code:

   <a onclick="confirm('mensagem de confirmação')" href= "close.php?id_os=<?php echo $temp['id']?>";>
        <div style="width:5%; height:100%">enviar
        </div>
    </a>

Obs: PHP entered is ok. In fact, as stated earlier, on any button I click (ok or Cancel), it sends the variable to the page in question.

  • 1

    Place a Return before confirm: Return confirm('confirmation message')

1 answer

2


You need to cancel the click event with a return false for example.
Like the confirm already returns true or false just use return confirm so in your example:

 <a onclick="return confirm('mensagem de confirmação')">

So if confirm will be directed (true), if cancel will not trigger the link (false)

Browser other questions tagged

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