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
Saurabh Sood 12Saurabh Sood 12 

Actionfunction value is not comming

Hi everyOne,

I have written first actionfunction code but it not calling to that scipt method as it supose to do so can anyone help me out withthis

This is my controller 
public class wrapperWithRadioButtonCtrl {
    List<Account> acc{get;set;}
    Public Integer records{get;set;}
    public String passedValue{get;set;}
    public wrapperWithRadioButtonCtrl(){
        acc = [select id, name, type from Account limit 10];
        records = acc.size();
        System.debug('Total records are '+ records);
        passedValue ='';
    }
    public List<Account> getaccounts(){
        return acc;
    }
    
    public pageReference dummyCall(){
        System.debug(passedValue);
        return null;
    }
        
}


Visualforce page

<apex:page Controller="wrapperWithRadioButtonCtrl" readOnly="true" >
   <apex:form >
       <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
        function MyFunction(){
        alert('hi');
            var i = {!records};
            var selectedRecordIds;
           for(j = 0; j < i; j++){
               console.log('value of j'+ j+'\n');
               if(document.getElementByName("SelectedAccount")[j].checked)
               {
                selectedRecordIds = document.getElementByName("SelectedAccount")[j].value;   
                  console.log('selected Record Id is'+ selectedRecordIds);
               }
           }
            passVariableToController(selectedRecordIds);
    </script>
 
        
    
    <apex:pageBlock >
        <table>
            <Tr><th>Selected Account</th>
            <th>Account Name</th>
            <th>Account Type</th>
           </Tr>
            <apex:repeat value="{!accounts}" var="a" >
            <tr>
                
                <td><input type="radio" value="{!a.id}" name="SelectedAccount"/> </td>
                <td><apex:outputText >{!a.name}</apex:outputText></td>
                <td><apex:outputText >{!a.type}</apex:outputText></td>
                
            </tr>
            </apex:repeat>
        </table>
    </apex:pageBlock>
    <apex:actionFunction name="passVariableToController" action="{!dummyCall}" reRender="pd2">
        <apex:param name="pi" assignTo="{!passedValue}" value="" />
    </apex:actionFunction>
    <apex:commandButton onclick="MyFunction(); return false;" value="Search" />
        <apex:pageBlock id="pb2" title="Account Value">
            <apex:outputText >{!passedValue}</apex:outputText>
       </apex:pageBlock>
     </apex:form>
</apex:page>
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Saurabh, 

Replace the line   var i = {!records}; with , 

 
var i = '{!JSENCODE(records)}';

--PS