How to use JavaScript Confirm() box in HTML

In this asp.net article i will explain how to use javascript confirm box in HTML.

Confirmation javascript used to confirm an important actions that are taking place on a website. For example, they may be used to confirm an order submission or logout from the website, change the login password we confirm that action before they done..

JavaScript confirm box pops up, the user will have two option  OK or Cancel.

Here we will learn with an HTML Example.

Write javascript confirm() box code in <head> tags like below :

<head runat=”server”>
<script type=”text/javascript” language=”javascript”>
function mm()
{
var my = confirm(“Do you want to Exit?”);
if( my == true )
{
alert(“Ok, Thank you Bye Bye.”);
return true;
}
else
{
alert(“Welcome back to system.”);
return false;
}
}
</script>
</head>

First Design HTML web form for learn javascript confirm() box.

Here is the asp.net Button control code :

<input id=”Submit1″ type=”submit” value=”Confirm Box()” onclick=”mm()” />

Here we use onclick property of button control for call javascript function.

JavaScript confirm box in HTML
JavaScript confirm box in HTML

Wen you click OK button on confirm box, Messagebox shows the “OK, Thank you Bye Bye”.

JavaScript confirm box in HTML
JavaScript confirm box in HTML

Wen you click Cancel button on confirm box, Messagebox shows the “Welcome back to System”.

JavaScript confirm box in HTML
JavaScript confirm box in HTML

I hope this HTML example of confirm box will help you……

Leave a Reply

Your email address will not be published. Required fields are marked *