Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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|improve this question
    
Here you go -> jsfiddle.net/x4CM3/1 –  adeneo Oct 4 '13 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. –  Temp Expt Oct 4 '13 at 14:33

2 Answers 2

up vote 1 down vote accepted

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/

share|improve this answer
    
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. –  Temp Expt Oct 4 '13 at 14:32
    
@TempExpt so you have to opened popup at the same time? Is something in modal? –  Irvin Dominin Oct 4 '13 at 14:37
    
no. it's not modal. –  Temp Expt Oct 4 '13 at 14:47
    
@TempExpt Take a look at this: jsfiddle.net/IrvinDominin/V9zMx/3 –  Irvin Dominin Oct 4 '13 at 14:50
    
Thank you very much. Thank a lot. It's working fine. I'm marking it as solved. –  Temp Expt Oct 4 '13 at 15:09

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

share|improve this answer
    
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. –  Temp Expt Oct 4 '13 at 14:31
    
@TempExpt, so you mean that at some time you will have 2 dialogs open? –  Sergio Oct 4 '13 at 14:33
    
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. –  Temp Expt Oct 4 '13 at 14:49
    
@TempExpt, you mean close the dialog with the checkbox and open a new one? –  Sergio Oct 4 '13 at 14:50
    
no. when i close the 2nd dialog, then checkbox(in first dialog) will be unchecked. I got solution from Irvin below. Thank you. –  Temp Expt Oct 4 '13 at 15:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.