Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to display yes or no dialog in javascript or jquery

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate Numbers in JQuery file 11 66
Html CheckBox obtain Its Value 5 27
on window close, not beforeunload 6 17
How to make button inactive until I fill in all the boxes. 11 18
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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)

856 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