Bruce Stemplewski
Bruce Stemplewski

Reputation: 1343

Select all items in checkbox group with CSJS?

I am able to select all of the items in a checkbox group with SSJS by simply setting the component's value.

But how would I do this in CSJS?

Upvotes: 0

Views: 1201

Answers (4)

Leon Matthys
Leon Matthys

Reputation: 67

Simplifying Naveen's answer, this worked great for me:

dojo.query("input[name=\"#{id:checkBoxGroup1}\"]").forEach( function(node) {
        node.checked = true; 
    });

Upvotes: 1

Thomas Adrian
Thomas Adrian

Reputation: 3636

this is how you do it in jquery

$("[name$=checkBoxGroup1]").attr("checked",true)

Upvotes: 1

Naveen
Naveen

Reputation: 6936

Assuming that the name of your check box group is checkBoxGroup this code snippet of check all checkbox should do the trick for you.

<xp:checkBox text="Check all" id="chkCheckAll">
    <xp:eventHandler event="onclick" submit="false">
        <xp:this.script><![CDATA[dojo.query("input[name=\"#{id:checkBoxGroup}\"]").forEach(
    function(node) {
        node.checked = document.getElementById("#{id:chkCheckAll}").checked;
    }
)]]></xp:this.script>
    </xp:eventHandler>
</xp:checkBox>

Upvotes: 4

stwissel
stwissel

Reputation: 20384

You select them with dojo.query and set the selected property to true. You need to check: every box will have its own ID, but the beginning of it is the same -or- you use a class. Or you look for the first and then select all siblings.

The strategy depends on your application's needs.

Check the dojo.query documentation for your options.

Upvotes: 2

Related Questions