How to show confirm box or popup in jquery with confirm and cancel buttons.

Spread the love with your friends

confirm box in jQuery
confirm box in jQuery

Dear friends, Today we will discuss about how to show a confirm popup box in jquery. Here we will demonstrate a code that help us to show POP-UP in jQuery or in Java Script with multiple choice buttons like OK button or cancel button and how to work these button respectively when a user click on those buttons.

We will also demonstrate through the code when a user click on any one of them button then how to run code as per respective button clicks.

So guys lets start : First of all i will give the code . The code for a Pop-Up in jQuery is below:

<script>
function myFunction() {
var txt;
var r = confirm(“Press a button!”);
if (r == true) {
txt = “You pressed OK!”;
} else {
txt = “You pressed Cancel!”;
}
document.getElementById(“demo”).innerHTML = txt;
}
</script>

About the code :

So guys the above code we write for jQuery pop-up. Here in this code we write a function with the name myFunction(), that have a variable named ‘var txt’  which is used to display the message when someone click on a multiple choice button on pop-up. Suppose when you click on a Confirm button then the message will display like “You pressed OK !” and when someone click the cancel button then the message will be display “You pressed Cancel”.

for operational you can perform action on confirm button by using this code:

var r = confirm(“Press a button!”);
if (r == true) {
txt = “You pressed OK!”;
}

and you can perform the action on cancel in this given code :

else {
txt = “You pressed Cancel!”;
}

I hope you guys understood this code and demonstration about how to POP-UP work in jQuery and in JavaScript.

If you like this post and want to know more about in jQuery or Java Script you can comment below us. Thanks.


Spread the love with your friends

Leave a Comment

PHP Code Snippets Powered By : XYZScripts.com