Solved

How to display yes or no dialog in javascript or jquery

Posted on 2014-03-04
5
1,500 Views
Last Modified: 2014-03-05
I have a button in my page like this

<div class="buttonHolder">
                        <input valign="center" name="Button3" id="btnSubmitchanges" type="button" value="Submit Changes" style="background-color:#A9E2F3; font-size: 12px; font-weight:bold; visibility:;"  />
       </div>

When I click the above button I want to display yes or no dialog box and wants to return the value based on user clicks 'yes' or 'no' button.

Thanks
0
Comment
Question by:bujjigadu
5 Comments
 
LVL 15

Expert Comment

by:Minh Võ Công
ID: 39905395
$mydialog = $("#dialog").dialog({
    autoOpen: false,
    buttons: {
        "ok": function() {
            $(this).dialog("close");
            processResult(true);
        },
        "cancel": function() {
            $(this).dialog("close");
            processResult(false);
        }
    }
});

$mydialog.dialog("open");


function processResult(result) {
    alert(result);
}
0
 
LVL 7

Accepted Solution

by:
Kishan Zunjare earned 300 total points
ID: 39905420
Custom yes no dialogue box by using jQuery

http://jsfiddle.net/kishanzunjare/tswrR/

Hope this helps
-Kishan
0
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 39905839
Without jQuery and or jQuery.UI libraries a simple confirm would suffice.
<div class="buttonHolder">
    <input valign="center" name="Button3" id="btnSubmitchanges" type="button" value="Submit Changes" style="background-color:#A9E2F3; font-size: 12px; font-weight:bold; visibility:;"
onclick="return confirm('Are you sure ?');"  />
</div>

Open in new window

0
 

Author Comment

by:bujjigadu
ID: 39906607
Minh,

How to call this from the button

$mydialog = $("#dialog").dialog({
    autoOpen: false,
    buttons: {
        "ok": function() {
            $(this).dialog("close");
            processResult(true);
        },
        "cancel": function() {
            $(this).dialog("close");
            processResult(false);
        }
    }
});

$mydialog.dialog("open");


function processResult(result) {
    alert(result);
}
0
 
LVL 15

Expert Comment

by:Minh Võ Công
ID: 39908250
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now