onclick "confirm" does not work cancel button

0

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

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

Follow 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: The inserted PHP is ok. In fact, as stated earlier, on whatever button I click (ok or cancel), it sends the variable to the page in question.

    
asked by anonymous 27.03.2018 / 14:26

1 answer

2

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

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

So if you confirm it will be directed ( true ), if cancel the link will not be triggered ( false )

    
27.03.2018 / 14:39