How to get JavaScript confirmation message?

Posted by Raja under JavaScript category on | Views : 7860
If we want to get the JavaScript confirmation message on click of a button or link, we can use following code.

 <span onclick="return confirm('Are you sure to DELETE the record?')">
<a href="gotothispage.aspx?delete=12" title="Delete">Delete</a>

In place of anchor tag highlighted above, we can place button, link button, html buttons or any other controls etc. confirm("xxxxx") function returns true if clicked OK button else it returns false, so you can also store its value into a javascript variable like.

var returnValue = confirm("Are you sure?");

if user clicks OK button in the confirmation box, returnValue will have true otherwise false.

Comments or Responses

Login to post response