0

I have a checkbox that when gets clicked will open up a dialog. If "Done" is clicked, I want the checkbox to have a checkmark. If "Cancel" is clicked, I want the checkbox not to have a checkmark.

Currently, I cannot get the checkbox to be set while using this code:

    <script type="text/javascript">
            $(document).ready(function() {
                    var dialog = $("#test-dlg").dialog({
                            modal:true,
                            autoOpen:false,
                            buttons: {
                                    "Done": function() { $("#test-chk").attr("checked", "checked"); $(this).dialog("close"); },
                                    "Cancel": function() { $("#text-chk").removeAttr("checked"); $(this).dialog("close"); }
                            }
                    });

                    $("#test-chk").click(function(e) {
                            dialog.dialog('open');
                            e.preventDefault();
                    });
            });
    </script>
</head>
<body>
    <form action="#">
            <input type="checkbox" id="test-chk" /><label for="test-chk">Testing</label>
    </form>
</body>
<div id="test-dlg">
    <p>Test Dialog</p>
</div>

1 Answer 1

2

You are using jQuery 1.6, so you need to use .prop() instead of .attr().

change this: $("#test-chk").attr("checked", "checked");

to this: $("#test-chk").prop("checked", "checked");

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

1 Comment

Thanks! You replied just as I found the answer here: blog.jquery.com/2011/05/12/jquery-1-6-1-released

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.