admin管理员组

文章数量:1295277

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.

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.

Share edited Oct 4, 2013 at 14:31 asked Oct 4, 2013 at 12:50 user1527336user1527336 2
  • Here you go -> jsfiddle/x4CM3/1 – adeneo 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. – user1527336 Commented Oct 4, 2013 at 14:33
Add a ment  | 

2 Answers 2

Reset to default 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/IrvinDominin/V9zMx/

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

本文标签: javascriptHow to open jQuery dialog on html CheckBox checked(using jQuery)Stack Overflow