admin管理员组

文章数量:1434922

I want to get p:selectBooleanCheckbox ponent 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

I want to get p:selectBooleanCheckbox ponent 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

Share Improve this question edited Jul 28, 2016 at 16:28 Zakaria Acharki 67.5k15 gold badges78 silver badges106 bronze badges asked Jul 21, 2016 at 14:18 Raied RaafatRaied Raafat 1031 gold badge3 silver badges11 bronze badges 3
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. – Zakaria Acharki Commented Jul 21, 2016 at 14:29
  • Look this answer stackoverflow./a/11441530/6065134 – Artem Commented Jul 21, 2016 at 15:06
  • @ZakariaAcharki i added sample of my code, sorry i still beginner in stackoverflow – Raied Raafat Commented Jul 27, 2016 at 8:33
Add a ment  | 

1 Answer 1

Reset to default 4

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')

本文标签: htmlHow to know that primefaces selectBooleanCheckbox is selected or not using javascriptStack Overflow