0
votes

I have a repeat control that calls data from an sql table with javascript. The repeat has a column name with data from the table and another column with a check box in it. The check box is ticked to store the data from the repeat in a separate table. I want to clear all check boxes in the repeat when a button is clicked. How do I do that?

Heres what I've tried.

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xe="http://www.ibm.com/xsp/coreex"
    xmlns:xc="http://www.ibm.com/xsp/custom">

    <xp:this.resources>
        <xp:script src="/scriptsNewConflictRequest.jss" clientSide="false"></xp:script>
    </xp:this.resources>
    <xp:repeat id="repeat1" rows="30" var="rowData" value="#{javascript:getBusinessUnitsCR()}">
        <xp:table style="width:99.0%">
            <xp:tr>
                <xp:td style="width:50.0%">
                    <xp:label value="#{javascript:rowData.busUnit}" id="label4"></xp:label>
                </xp:td>
                <xp:td align="center" style="width:20%">
                    <xp:checkBox text="Yes" id="checkBU" checkedValue="Yes" uncheckedValue="No">
                        <xp:eventHandler event="onchange" submit="true" refreshMode="norefresh"
                         id="eventHandler1">
                            <xp:this.action><![CDATA[#{javascript:saveOrDelBU();}]]</xp:this.action>
                        </xp:eventHandler>
                    </xp:checkBox>
                </xp:td>
            </xp:tr>
        </xp:table>
    </xp:repeat>

    <xp:button value="Clear Check Boxes" id="button3">
        <xp:eventHandler event="onclick" submit="true" refreshMode="complete" id="eventHandler4">
            <xp:this.action><![CDATA[#{javascript:
                                       //Method 1
                                       getComponent("checkBU").setValue("No");}]]>//Did Not Work
                                      //Method 2 
                                      context.redirectToPage(context.getUrl().toString());//Does not help because the page is on a switch facet and it does not redirect back to this page.
            </xp:this.action>
        </xp:eventHandler>
    </xp:button>
</xp:view>

Tried the two methods listed above. Not sure what else to try.

1

1 Answers

2
votes

If you just want to do this client-side, you can use some code like in this example:

<xp:button value="Select All" id="button6" styleClass="button">
    <xp:eventHandler event="onclick" submit="false" id="eventHandler3">
        <xp:this.script><![CDATA[var els= XSP.getElementById("#{id:someDiv}").getElementsByTagName("input");
for(var el= els.length-1; el>=0; el--)
    if(els[el].type=="checkbox")
        els[el].checked= true;]]></xp:this.script>
    </xp:eventHandler>
</xp:button>