最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

html - How to know that primefaces selectBooleanCheckbox is selected or not using javascript? - Stack Overflow

matteradmin5PV0评论

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')
Post a comment

comment list (0)

  1. No comments so far