javascript confirm function return false
confirm, javascript
Solution
You need to use the return value:
<a onclick="return askCar();" ... >
Just having it inside the `onclick` will execute the function but to actually cancel the click, you need to use the return value.
Also, the code can be slightly optimized:
function askCar(){
return confirm ("Are you sure for deleting car ?");
}
No need in `if..else` when you can directly return the dialog result. (unless of course you want to perform exra actions)
Problem
I want to show a message which writing are you sure … I can show the message but user click NO `return false;` did not work ``` <script> function askCar(){ var answer = confirm ("Are you sure for deleting car ?"); if (answer){ } else{ return false; } } </script> ``` I call function with onclick here ``` echo '<td><a onclick="askCar()" href="arac-sil.php?sid='.$data["Car_ID"].'" class="ico del">Sil</a><a href="arac-duzenle.php?did='.$data["Car_ID"].'" class="ico edit">Düzenle</a></td>'; ```