4

I want to popup a jQuery dialog when a html checkbox is checked. I'm using following code. But it's not working.

$(document).ready(function () {
        $('#chkBoxHelp').click(function () {
            if ($(this).is(':checked')) {
                $("#txtAge").dialog();
            }
        });
    });

And the html is as below:

<input type="checkbox" id="chkBoxHelp"/>
<div id="txtAge" style="display: none;">Age is something</div>

Please help me.

Also I want to uncheck the checkBox when popup will be closed. Checkbox is in a jQuery popup box. I need to open another popup on checkbox checked.

Thanks in Advance.

2
  • Here you go -> jsfiddle.net/x4CM3/1 Commented Oct 4, 2013 at 12:55
  • Hi Adeneo, thanks for your response. It's working fine in asp page. I forget to mention that the checkbox is in a jQuery popup. I need to open another popup on checkbox checked. I've also updated the question. Please help. Commented Oct 4, 2013 at 14:33

2 Answers 2

3

You can use open and close methods and close event.

Code:

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

Demo: http://jsfiddle.net/IrvinDominin/V9zMx/

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, thanks for your response. It's working fine in asp page. I forget to mention that the checkbox is in a jQuery popup. I need to open another popup on checkbox checked. I've also updated the question. Please help.
@TempExpt so you have to opened popup at the same time? Is something in modal?
Thank you very much. Thank a lot. It's working fine. I'm marking it as solved.
2

Try this, also closing if the checkbox is clicked again.

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

Demo here

5 Comments

Hi, thanks for your response. It's working fine in asp page. I forget to mention that the checkbox is in a jQuery popup. I need to open another popup on checkbox checked. I've also updated the question. Please help.
@TempExpt, so you mean that at some time you will have 2 dialogs open?
not at the same time. when i click on a button a div is opening as a popup. the div contains a checkbox. now i want another popup on checkbox checked.
@TempExpt, you mean close the dialog with the checkbox and open a new one?
no. when i close the 2nd dialog, then checkbox(in first dialog) will be unchecked. I got solution from Irvin below. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.