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
Radha Rathinavel PandianRadha Rathinavel Pandian 

How to pass the java array values to the save the record in Visualforce page

Hi 

I have a Java script values stored in name  "radArray" in visualforce page. How can I pass this values to get insert on clicking save button from below command button from visualforce page to class.

<apex:commandButton value="Save" action="{!save}">
Radha Rathinavel PandianRadha Rathinavel Pandian
Hi
Could you please tel me how to integrate in button save.
<apex:commandButton value="Save" action="{!test}" />
JAYABALAJI TKM 1JAYABALAJI TKM 1
Hi Radha,

Please check below link

http://sfdcsrini.blogspot.com/2014/07/visualforce-action-function-example.html
Controller Class:


public class ActionFunctionCLS {
  public Account actObj{get;set;}
   PageReference prf= null;
    public ActionFunctionCLS(){
      actObj = new Account();
    }
 
   
    public pagereference Saverec(){
   if(actobj.Name !=''){
    insert actobj;
   
   }
   else{
     ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Please Enter Name.');
     ApexPages.addMessage(myMsg);
   
   }
   if(actobj.id !=null){
  
      // Send the user to the detail page for the new account.
      prf = new PageReference('/'+actobj.id);
      prf.setRedirect(true);
   
   }
   return prf;
    }

}


Visualforce Page:

<apex:page controller="ActionFunctionCLS" id="pg" >
  <script>
   function recSave(){
    var accountType = document.getElementById('pg:fm:pb:pbs:actType').value;
    alert('accountType -->'+accountType);
    if(accountType != 'Prospect'){
     alert('You Should Select Prospect to Save the Record');
     return false;
    }
    else{
     saveAccount(); //this is the function name which calls our action function from java Script.
     return true;
    }
   }
 
  </script> 

 <apex:form id="fm">
  <apex:actionfunction name="saveAccount" action="{!Saverec}" />
   <apex:pageBlock id="pb">
     <apex:pagemessages ></apex:pagemessages>
     <apex:pageblockButtons >
      <apex:commandButton value="Save" onclick="recSave();return false;"/>    
     </apex:pageblockButtons>
    
     <apex:pageblockSection id="pbs">
       <apex:inputField value="{!actobj.Name}" id="actName"/>
       <apex:inputField value="{!actobj.type}" id="actType"/>
     </apex:pageblockSection>
   </apex:pageBlock>
 </apex:form>
</apex:page>
In command button onclick event need to give javascript function and from javascript fuction we need to call action function name, While calling time we need pass array to param tag.

If this help for you make it Best Ans

Thanks 
Jayabalaji