+ Start a Discussion
Vigneshwaran LoganathanVigneshwaran Loganathan 

Checking all records using Javascript Issue

Hi,
I have written Javascript to check all records using Checkbox, Plz see the snapUser-added image

Its working well but after a while it goes like below snap,

User-added image

My VF
<apex:page standardController="Payment__c" extensions="paymentController" id="page1">
<script>
function checkAll(cb,cbid)
{
    var inputElem = document.getElementsByTagName("input");                    
    for(var i=0; i<inputElem.length; i++)
    {            
        if(inputElem[i].id.indexOf(cbid)!=-1){                                       
        inputElem[i].checked = cb.checked;
        }
    }
}
function checkAll1(cb,cbid)
{
    var inputElem = document.getElementsByTagName("input");                    
    for(var i=0; i<inputElem.length; i++)
    {            
        if(inputElem[i].id.indexOf(cbid)!=-1){                                       
        inputElem[i].checked = cb.checked;
        }
    }
}
<apex:pageblockSection title="Payslip Selection" columns="1" rendered="{!paysec}" id="pb1s2">
            <apex:dataTable value="{!payslip}" var="pay" columnswidth="50px,50px" cellpadding="4" border="1" align="center" id="datatable">
                <apex:column >
                    <apex:facet name="header">
                        <apex:inputCheckbox >
                            <apex:actionSupport event="onclick" action="{!Getselected}" onsubmit="checkAll(this,'checkedone')" rerender="checkedone"/>
                        </apex:inputCheckbox>                  
                    </apex:facet>  
                    <apex:inputCheckbox value="{!pay.selected}" id="checkedone">
                        <apex:actionSupport event="onclick" action="{!GetSelected}" rerender="Selected_PBS1"/>
                    </apex:inputCheckbox>
                </apex:column> 
                <apex:column headervalue="Payslip Name" value="{!pay.payslp.Name}" />
                <apex:column headervalue="VA Name" value="{!pay.payslp.Name__c}" />
                <apex:column headervalue="Bank Account" value="{!pay.payslp.Account_Number__c}"/>
                <apex:column headervalue="Bank Account" value="{!pay.payslp.Account_Number__c}"/>                
                <apex:column headervalue="Total Pay in Dollar" value="{!pay.payslp.Total_Pay_for_this_period__c}"/> 
                <apex:column headervalue="Total Pay in Peso" value="{!pay.payslp.Total_Pay_in_Peso__c}"/>                                        
            </apex:dataTable>
 </apex:pageblockSection>
Hope you can help,

Thanks.
 
Best Answer chosen by Vigneshwaran Loganathan
Mohit Bansal6Mohit Bansal6
<apex:page standardController="Payment__c" extensions="paymentController" id="page1">
<script>

function checkAll(obj,cbid){
            var inputCheckBox = document.getElementsByTagName("input");                  
            for(var i=0; i<inputCheckBox.length; i++){          
                if(inputCheckBox[i].id.indexOf(cbid)!=-1){                                     
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }

</script>

<apex:pageblockSection title="Payslip Selection" columns="1" rendered="{!paysec}" id="pb1s2">
            <apex:dataTable value="{!payslip}" var="pay" columnswidth="50px,50px" cellpadding="4" border="1" align="center" id="datatable">
                

                 <apex:column style="width:50px;">
                    <apex:facet name="header">
                                <apex:inputCheckbox onclick="checkAll(this,'checkedone')"/>
                    </apex:facet>
                    <apex:inputCheckbox value="{!pay.selected}" id="checkedone"/>
                </apex:column>

                <apex:column headervalue="Payslip Name" value="{!pay.payslp.Name}" />
                <apex:column headervalue="VA Name" value="{!pay.payslp.Name__c}" />
                <apex:column headervalue="Bank Account" value="{!pay.payslp.Account_Number__c}"/>
                <apex:column headervalue="Bank Account" value="{!pay.payslp.Account_Number__c}"/>                
                <apex:column headervalue="Total Pay in Dollar" value="{!pay.payslp.Total_Pay_for_this_period__c}"/> 
                <apex:column headervalue="Total Pay in Peso" value="{!pay.payslp.Total_Pay_in_Peso__c}"/>                                        
            </apex:dataTable>
 </apex:pageblockSection>

I have made correction to your code and i hope it will work as per your expectation. Kindly try and share your views.


Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help

All Answers

ManojjenaManojjena
Hi  Vigneshwaran,

Issue is with reRender with actionsupport ,Please check and let me know .
Mohit Bansal6Mohit Bansal6
<apex:page standardController="Payment__c" extensions="paymentController" id="page1">
<script>

function checkAll(obj,cbid){
            var inputCheckBox = document.getElementsByTagName("input");                  
            for(var i=0; i<inputCheckBox.length; i++){          
                if(inputCheckBox[i].id.indexOf(cbid)!=-1){                                     
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }

</script>

<apex:pageblockSection title="Payslip Selection" columns="1" rendered="{!paysec}" id="pb1s2">
            <apex:dataTable value="{!payslip}" var="pay" columnswidth="50px,50px" cellpadding="4" border="1" align="center" id="datatable">
                

                 <apex:column style="width:50px;">
                    <apex:facet name="header">
                                <apex:inputCheckbox onclick="checkAll(this,'checkedone')"/>
                    </apex:facet>
                    <apex:inputCheckbox value="{!pay.selected}" id="checkedone"/>
                </apex:column>

                <apex:column headervalue="Payslip Name" value="{!pay.payslp.Name}" />
                <apex:column headervalue="VA Name" value="{!pay.payslp.Name__c}" />
                <apex:column headervalue="Bank Account" value="{!pay.payslp.Account_Number__c}"/>
                <apex:column headervalue="Bank Account" value="{!pay.payslp.Account_Number__c}"/>                
                <apex:column headervalue="Total Pay in Dollar" value="{!pay.payslp.Total_Pay_for_this_period__c}"/> 
                <apex:column headervalue="Total Pay in Peso" value="{!pay.payslp.Total_Pay_in_Peso__c}"/>                                        
            </apex:dataTable>
 </apex:pageblockSection>

I have made correction to your code and i hope it will work as per your expectation. Kindly try and share your views.


Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
This was selected as the best answer
Vigneshwaran LoganathanVigneshwaran Loganathan
Hi Manoj Kumar jena,

As you said problem is with rernder only. fine now. Tnx.