Lavanya
Lavanya

Reputation: 621

How to show the confirmation alert with one button using javascript?

In my application, i need to show the message in alert with OK button.

In that button click event, i want to do some functionalities using the javascript.

So, how can i do this in my app?

Please let me know?

Upvotes: 3

Views: 25206

Answers (4)

Angel
Angel

Reputation: 1200

If you'll be using alert() then the execution of javascript will stop where the alert is written. And after the OK button is pressed, the code execution will resume. So, do an alert(message); and after that line, put the code you want to be executed after the OK button is pressed.

If you want more control, you can use jQuery UI Dialog.

Upvotes: 3

ClydeFrog
ClydeFrog

Reputation: 1012

Here's a simple example

if (confirm("Select a button")){
    alert("You selected OK");
}else{
    alert("You selected Cancel");
}

But if you're just looking for a popup with one button I would go for the alert()

alert("Press OK to close!");

For more popup examples, go to w3schools

Upvotes: 0

freakish
freakish

Reputation: 56467

Forget about built-in popups. Even if you make it work you'll probably hit some cross-browser issues and you won't be able to sleep (trust me: I know what I'm saying, I've been there). :)

I've been using jQuery UI ( link ) for some time and I am really satisfied with. Give it a try!

Upvotes: 0

James Allardice
James Allardice

Reputation: 165971

I'm not entirely sure what you are trying to do, but you may be looking for the window.confirm function, which is a built-in function like alert that allows you to capture the response (true or false) from the user:

if(confirm("Some message")) {
    //Clicked ok
} else {
    //Clicked cancel
}

If you want more functionality than that I'm afraid you'll have to look elsewhere. There are endless modal scripts and libraries available, so just search for one that suits your needs.


Having re-read your question title, maybe you just want the normal window.alert function? That will display a dialog with one button, and, in general, prevent execution of the code following it until the user has closed it:

alert("Some message");

Upvotes: 9

Related Questions