Reputation: 103
I want to get p:selectBooleanCheckbox
component and check if it is selected or not using javascript
<h:dataTable value="#{controller.list}" var="item">
<h:column>
<f:facet name="header">Ratio1</f:facet>
<h:panelGrid columns="2">
<p:inputText id="ratio1" readonly="#{true}" disabled="true" styleClass="ratio1"/>
<h:outputText value="%" />
</h:panelGrid>
<p:selectBooleanCheckbox id="report1" onchange="calculateTotalRatio()" value="#{controller.value}" valueChangeListener="#{fISHController.onCaseTestItemPatternReportFlagChange()}">
</p:selectBooleanCheckbox>
</h:column>
I want on calculateTotalRatio()
function check if the checkbox is checked or not and depending on it update ratio1 input text with value
Upvotes: 0
Views: 6117
Reputation: 596
You can define the widgetVar of your selectBooleanCheckbox
<p:selectBooleanCheckbox id="check" widgetVar="myCheckbox" value="#{myBacking.value}"/>
You can access in js the Primefaces object in these ways
directly with myCheckbox
PF("myCheckbox")
window["myCheckbox"]
PrimeFaces.widgets["myCheckbox"]
So, to get the checkbox state you can use
myCheckbox.input.is(':checked')
PF("myCheckbox").input.is(':checked')
window["myCheckbox"].input.is(':checked')
PrimeFaces.widgets["myCheckbox"].input.is(':checked')
Upvotes: 4