Solved

How to display yes or no dialog in javascript or jquery

Posted on 2014-03-04
5
1,548 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

896 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

18 Experts available now in Live!

Get 1:1 Help Now