function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
liron169liron169 

JQuery for update checkBox on list of record

Hello,

 

I have list of records in page with checkbox on each (with wrapper class).

I'm trying to write with JQuery that only one record will be selected at time.

 

Can someone advise what wrong with below script?

It's seems that this script update the wrong data + changing the order in the list...

 

<script>
        var j$ = jQuery.noConflict();
        jQuery(document).ready(function() {
jQuery(".selected-checkbox").click(function() {
var checkedRow = this;
        //alert('Hello world, part 2!'+ checkedRow );
 jQuery(".selected-checkbox").each(
            function() {
                this.checked= false;
            }
        );
checkedRow.checked= true;

});
});
     
</script>

digamber.prasaddigamber.prasad

Could you please share your code snippet, of course with simplified fields & hiding your business objective.

 

Happy to help you!

 

Regards,

Digamber Prasad

liron169liron169

Thanks for reply.

 

I'm adding the page code.

 

 

<apex:page standardController="Obj__c" extensions="vf_myPage">
<apex:includeScript value="{!$Resource.jquery172}"/>
<script>
        var j$ = jQuery.noConflict();
        jQuery(document).ready(function() {
jQuery(".selected-checkbox").click(function() {
var checkedRow = this;
        //alert('Hello world, part 2!'+ checkedRow );
 jQuery(".selected-checkbox").each(
            function() {
                this.checked= false;
            }
        );
checkedRow.checked= true;

});
});
     
</script>
<apex:form id="formid" >
<apex:pageBlock >
<apex:pageMessages />

<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>

<apex:pageBlockSection collapsible="false">

<apex:pageBlockTable value="{!lst_Wrapper}" var="s" id="table" align="center" border="0">

    <apex:column headerValue="Priority">
        <apex:outputField value="{!s.PRI__c}" id="priorityfieldid"/>
    </apex:column>
    <apex:column headerValue="Prefix">
        <apex:outputField value="{!s.name}" id="Nameid"/>
    </apex:column>
    <apex:column headerValue="Tag" width="50">
        <apex:inputCheckbox value="{!s.selected}" id="selectall" styleClass="selected-checkbox" >
    </apex:inputCheckbox>
    </apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

 

digamber.prasaddigamber.prasad

Could you also please share extensions, so that I can do dry run of your code.

 

Regards,

Digamber Prasad

liron169liron169

After further testing I found that it doesn't related to the JQuery.

Even if I remove it, when pressing save it select the wrong record.

 

Probably indeed related to the controller.

I'll check and raise issue if needed.