1

With regards to my previous question: Wrapper class' validation based on an Existing checkbox, I am trying to find a way to loop through the list of records in the wrapper class using the JavaScript, but I always end up with need of .length inclusion and unable to get the exact row comparison.

Does anyone encounter this scenario with pageBlockTable row items: When we are selecting a checkbox with respect to a row, we should be able to validate with another checkbox's value from that specific row.

1
  • 1
    Check my answer in your previous Question.
    – Saroj Bera
    Commented Mar 30, 2018 at 10:11

1 Answer 1

1

Probably the most straightforward way to do this is to make use of $Component:

<apex:page>
<apex:pageBlock id="pageBlock">
<apex:pageBlockTable id="pageBlockTable" >
<apex:column id="validationColumn">
    <apex:checkbox id="validation" />
</apex:column>
<apex:column>
    <apex:checkbox onchange="validate('{!$Component.pageBlock.pageBlockTable.validationColumn.validation}');" />
</apex:column>
</apex:pageBlockTable>
<script>
    function validate(validationID)
    {
        var validationVal = document.getElementById(validationID).checked;
    }
</script>
</apex:pageBlock>
</apex:page>

However, since you have to specify the whole DOM structure to get the ID, $Component might be a bit cumbersome in this case. If you want, you can instead search for the table row, then find the validation checkbox:

<apex:checkbox onchange="validate(this);" />

<script>
    function validate(elem)
    {
        while((elem = elem.parentElement) && elem.tagName != "TR");
        var validationVal = elem.querySelector('input[type="checkbox"][id*=validation]');
    }
</script>
1
  • I haven't tried the above solution as I got some other work around from Saroj Bera on my previous question. I assume your solution also should work, thus marking it. Thanks for your time, I really appreciate it.
    – SatyaV
    Commented Apr 12, 2018 at 18:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .