Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hello,

I want to open a popup when a check-box is checked and when we close the popup check-box automatically unchecked and one more thing i want to add a save button in popup.


I am using following code. But it is not working.

$(document).ready(function () {
    var the_checkbox = $('#chkBoxHelp');
    the_checkbox.click(function () {
        if ($(this).is(':checked')) {
            $("#txtPopup").dialog({
                close: function () {
                    the_checkbox.prop('checked', false);
                }
            });
        } else {
            $("#txtPopup").dialog('close');
        }
    });
});


And the html is as below:
<input type="checkbox" id="chkBoxHelp"/>
<div id="txtPopup" style="display: none;">hello! It is a popup</div>


But I don't know why this is not work.
Posted
Updated 3-Mar-15 5:30am
v4
Comments
Thanks7872 3-Mar-15 7:24am    
And your question is?
[no name] 3-Mar-15 7:43am    
Where is checkbox?its on popup window ?
Deepak Tiwari (D'pak) 3-Mar-15 7:54am    
check-box is in a div, not on popup.
[no name] 3-Mar-15 7:56am    
chk my below code its working fine.ref this link : http://jsfiddle.net/dpauz/ and change the javascript in that site and put my below java script code.
[no name] 3-Mar-15 8:43am    
r u chkd the below code??

Hi,

Ref: Popup window when checkbox checked in asp.net

Eg:

XML
<form id="CheckoutOptions" name="CheckoutOptions">
    <label class="inline">
        <input type="checkbox" id="Register" name="CheckoutOptions" value="Register">Register Account</label>
    <br>
    <label class="inline">
        <input type="checkbox" id="Guest" name="CheckoutOptions" value="Guest">Guest Checkout</label>
</form>


JavaScript
$("#Register").click(function (e) {
     if ($(this).is(':checked')) {
var m= confirm("your message");
        if(m !=true)
          {
              $(this).removeAttr('checked');
              e.preventDefault();
           }
     }

 });
 
Share this answer
 
v2
You have to learn to read up the relevant documentation Dialog Widget[^].
I just did a quick reference and got this:
XML
<!DOCTYPE html>
<html>
   <head>
      <title>jQuery UI Dialog functionality</title>
      <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
      <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
      <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

      <script>
         $(function() {

            var dialog1 = $("#dialog1");
            var checkbox1 = $("#checkbox1");

            dialog1.dialog({
               autoOpen: false,
               modal: true,
               buttons: {
                  Save: function() {$(this).dialog("close");}
               },
               title: "Title here",
               close : function() {checkbox1.prop('checked', false);}

            });

            checkbox1.click(function() {
               if (checkbox1.prop("checked")) {
                   dialog1.dialog("open");
               }
            });

         });
      </script>
   </head>
   <body>
      <div id="dialog1">Hello, my dialogue.</div>
      <input type="checkbox" id="checkbox1">Open Dialog...
   </body>
</html>
 
Share this answer
 
v2
Comments
Deepak Tiwari (D'pak) 3-Mar-15 11:32am    
It is working well....
Deepak Tiwari (D'pak) 3-Mar-15 12:05pm    
Hi,

I want to add one another button in this popup. I am trying many times but I am not success.
Peter Leow 3-Mar-15 19:44pm    
You can add multiple buttons by:
buttons: {
Save: function() {$(this).dialog("close");},
Ok: function() {$(this).dialog("close");}
},
I take it that I have answered your question.
[no name] 3-Mar-15 23:23pm    
Correct one Peter Leow :)
Deepak Tiwari (D'pak) 4-Mar-15 12:21pm    
working well, thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900