-1

I have a JavaScript function and I want to assign checked value to fixedLoss() JavaScript function. I call fixedLoss() function but I don't take checked value info with PrimeFaces.

<p:selectBooleanCheckbox id="fixedLossId" value="#{chargebackBean.selectedChargebackCategory.fixedLoss}">
    <p:ajax event="change" update="fixedLossDateTime" oncomplete="fixedLoss()" />
</p:selectBooleanCheckbox>

<script>
    function fixedLoss() {
        if (fixedLossSelected ??) {
            ...
        }
        else {
            ...
        }
    }
</script>
Yasin
  • 123
  • 1
  • 12
  • 1
    1: please correct your title... `p:selectedChekboc`? 2: please post version info, 3: Search.... https://stackoverflow.com/questions/21183078/how-to-get-a-value-of-jsf-selectbooleancheckbox-by-using-javascript 4: please state what you tried to access it. – Kukeltje Jul 08 '19 at 08:58
  • `p:selectedCheckbox` ??? – Kukeltje Jul 08 '19 at 09:19
  • Using prime faces liblary ı will edit this tittle @Kukeltje – Yasin Jul 08 '19 at 09:31
  • You can also get it using jQuery like `jQuery("[id$='fixedLossId']").find("input").attr("aria-checked");` – Parkash Kumar Jul 08 '19 at 10:41

1 Answers1

1

You must add a widgetVar attribute to your widget:

<p:selectBooleanCheckbox id="fixedLossId"
                      value="#{chargebackBean.selectedChargebackCategory.fixedLoss}"
                      widgetVar="checkBox"
                      >
    <p:ajax event="change" update="fixedLossDateTime" oncomplete="fixedLoss()" />
</p:selectBooleanCheckbox>

And then use it to access to the control:

 $(PF('checkBox').input).is(':checked');
Oscar Pérez
  • 4,377
  • 1
  • 17
  • 36
  • Thanks @Oscar I will try. this seems to solution – Yasin Jul 08 '19 at 09:37
  • 1
    Like in here: https://stackoverflow.com/questions/38506746/how-to-know-that-primefaces-selectbooleancheckbox-is-selected-or-not-using-javas – Kukeltje Jul 08 '19 at 09:54