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
❤Code❤Code 

copy rows data from one row to another salesforce

Hi All,

I am trying to copy the values from one previous row to current one. Below is the javascript i am trying, but i am not getting - 

Below is vf page  & Javascript- 
 
<apex:page standardController="RFP__c" extensions="RFPController" sidebar="false" standardStylesheets="false">
    
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <c:FixSfdcFocusHack />
    <c:JQuery />
    <c:Chosen />

    <apex:form >
        <apex:pageBlock id="pb">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!Cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
            
           <apex:pageBlockSection title="Business RFP Details" columns="1" collapsible="false">
                
                <apex:inputField value="{!accounts.Name}" />
                <apex:inputField value="{!accounts.Date_Requested__c}" />
                <apex:inputField value="{!accounts.Industry__c}" />
                <apex:inputField value="{!accounts.Primary_Contact__c}" />
                <apex:inputField value="{!accounts.Client_Advertiser__c}" />
                <apex:inputField value="{!accounts.Agency__c}" />
                <apex:inputField value="{!accounts.Renewal__c}" />
                <apex:inputField value="{!accounts.Rep_Name__c}" />
                <apex:inputField value="{!accounts.Account_Clearance__c}" />
                <apex:inputField value="{!accounts.Client_Budget__c}" />
                <apex:inputField value="{!accounts.Campaign_Marketing_Objectives__c}" />
                <apex:inputField value="{!accounts.Campaign_Name_Identifer__c}" />  
                
            </apex:pageBlockSection>  
            
            <apex:pageMessages />
            <apex:outputText rendered="{!isRerender}">
                
            </apex:outputText>      
            <apex:variable var="rowNumber" value="{!0}"/>
            
            
            <apex:pageBlockSection title="Child RFP Details" collapsible="false" id="section">
                
                
                <apex:pageBlockTable id="thetable"  var="acc" value="{!attendeeList1}" onRowMouseOver="removeHighlight(this)">
                    
                    <!--  <apex:column headerValue="Action" >-->
                       <!-- <apex:commandLink value="Copy" reRender="pb" onclick="testMe(rowNumber)" oncomplete="renderChosen()" /> -->
                        <apex:column headerValue="Copy" >
                    <apex:inputCheckbox value="{!acc.radiochk}" label="Copy">
                           <apex:actionSupport event="onchange" action="{!addRow}" rerender="pb"  oncomplete="renderChosen()" status="actStatusId"/>
  
                            </apex:inputCheckbox>
                    </apex:column>
                    
                    <apex:column headerValue="Custom Package">
                        <apex:param name="rowIndex" value="{!rowNumber}"/>
                        
                        <apex:selectList multiselect="true" value="{!acc.discountSchedule}"  styleClass="fullWidth chzn-select" size="1" style="width:400px;" id="cp" >
                            <apex:actionSupport event="onchange" action="{!acc.updateMarketOptions}" rerender="geographies,mar" oncomplete="renderChosen()" />
                            <apex:selectOptions value="{!acc.Items}"/>
                        </apex:selectList> 
                        <apex:variable var="rowNumber" value="{!rowNumber+1}"/> 
                    </apex:column>
                    
                    
                    <apex:column headerValue="Market" id="market">
                        <apex:outputPanel id="geographies" layout="block" >
                            
                            <apex:selectList id="selectedmarkets" multiselect="false" value="{!acc.discountSchedule1}"  styleClass="fullWidth chzn-select " size="1" style="width:150px" >
                                <apex:actionSupport event="onchange" action="{!acc.updateRestOptions}" rerender="state,First,second,third,forth,fifth" oncomplete="renderChosen()" />
                                <apex:selectOptions value="{!acc.marketOptions}"/>
                            </apex:selectList> 
                            
                        </apex:outputPanel>
                    </apex:column>  
                    
                    
                    <apex:column id="state" headerValue="State" >
                        
                        <apex:inputField value="{!acc.cp.State__c}" styleClass="twitterStyleTextbox" id="st"/>
                    </apex:column>
                    <apex:column id="First" headerValue="First Issue" >
                        <apex:inputfield value="{!acc.cp.First_Issue__c}" styleClass="twitterStyleTextbox"/>
                    </apex:column>
                    <apex:column id="second" headerValue="Last Issue" >
                        <apex:inputField value="{!acc.cp.Last_Issue__c}" styleClass="twitterStyleTextbox"/>
                    </apex:column>
                    <apex:column id="third" headerValue="Circulation" >
                        <apex:inputField value="{!acc.cp.Circulation__c}" styleClass="twitterStyleTextbox"/>
                    </apex:column>
                    <apex:column id="forth" headerValue="Space Unit">
                        <apex:inputField value="{!acc.cp.Space_Unit__c }" styleClass="chzn-select"/>
                    </apex:column>
                    <apex:column id="fifth" headerValue="Per Unit Open Rate">
                        <apex:inputField value="{!acc.cp.Per_Unit_Open_Rate__c}" styleClass="twitterStyleTextbox"/>
                    </apex:column>
                    <apex:column id="six" headerValue="Space Discount">
                        <apex:inputtext value="{!acc.spacediscount}" styleClass="twitterStyleTextbox" id="sp" >
                            <apex:actionSupport event="onchange" action="{!acc.calculategrossrate}" rerender="seven"/>
                        </apex:inputtext>
                    </apex:column>
                    <apex:column id="seven" headerValue="Per Unit Gross Rate">
                        <apex:inputtext value="{!acc.perunitgross}" styleClass="twitterStyleTextbox" id="pg" html-readonly="true">
                            <apex:actionSupport event="onclick" action="{!acc.calculatetotalnet}" rerender="eight"/>
                        </apex:inputtext>
                    </apex:column>
                    <apex:column id="eight" headerValue="Total Net">
                        <apex:inputtext value="{!acc.totalnet}" styleClass="twitterStyleTextbox" id="tn" html-readonly="true">
                        <apex:actionSupport event="onclick" action="{!totalnetbottom}" rerender="tob"  oncomplete="renderChosen()"/>
                        </apex:inputtext>
                    </apex:column>
                    <apex:column width="25px" headerValue="Remove">
                        <apex:inputCheckbox value="{!acc.checked}">
                            <apex:actionSupport event="onchange" action="{!deleteLanguage}" rerender="pb"  oncomplete="renderChosen()"/>
                        </apex:inputCheckbox>
                    </apex:column>  
                </apex:pageBlockTable>
            </apex:pageBlockSection>
                        <apex:outputLabel id="tob" value="Total Net :" style="font-weight: bold;float:right; position: absolute;right:109px;">&nbsp;&nbsp;
            <apex:inputtext value="{!totalnetbottom}" styleClass="twitterStyleTextbox" id="tnb" html-readonly="true">
            
            </apex:inputtext>
            </apex:outputLabel>
            <apex:commandButton action="{!addRow}" value="Add Row" reRender="pb" oncomplete="renderChosen()"> 
                <apex:param name="rowIndex" value="{!rowNumber}"/>
            </apex:commandButton>
            <apex:outputText rendered="{!isRerender}">
      
        <script type="text/javascript">
            var table = document.getElementById('{!$Component.pb.thetable}');
                alert(table);
            var lastRow = table.rows[table.rows.length - 1];
            var prevRow = table.rows[table.rows.length - 2];
            var arrSourceInputs = prevRow.getElementsByTagName("input");
            var arrDestInputs = lastRow.getElementsByTagName("input");
            for(var i in arrSourceInputs){
                if(arrSourceInputs[i].type == "text"){
                    arrDestInputs[i].value = arrSourceInputs[i].value; 
                }
            }
        </script> 
        
      </apex:outputText>        
        </apex:pageblock>
    </apex:form>
</apex:page>
I kept an alert in the javascirpt .. On fired i am getting null..

Regards
Andy BoettcherAndy Boettcher
You cannot add a row to your "attendeeList1" controller list variable via Javascript/client-side only.  You need to either go 100% server-side (AJAX/rerender) or commit to the client-side (JS arrays and using ActionFunctions/RemoteMethods to push data to the controller).
James LoghryJames Loghry
Looks like your id selector is incorrect.  Try changing var table = document.getElementById('{!$Component.pb.thetable}'); to:
 
var table = document.getElementById('{!$Component.pb.section.thetable}');

If that doesn't work, then play around with the id until you get it correct.  You can do this pretty easily using Chrome's developer tools and the javascript console it comes with.
❤Code❤Code
Hi James/Andy,

Is it possible through Apex controller methods.

Regards