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
David9133David9133 

Handling the radiobutton value and selected record id in Controller

I want to capture both the Record Id and the selected Radio Button value and pass it to the controller and create new Child object record with the selected values only process the selected records.


Visualforce Code:
<apex:page controller="skillproficiencycontroller" >
<apex:form >
<script> function myFunction( val){ var x = val.value; callfunc(x); } </script>
<apex:pageBlock > <
apex:pageblockTable value="{!skilllist}" var="s">
<apex:column value="{!s.Name}"/>
<apex:column headerValue="Proficiency">
<apex:selectRadio value="{!Selected}" onclick="myFunction(this);">
<apex:selectOptions value="{!items}" /> </apex:selectRadio>
</apex:column>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller:
public with sharing class skillproficiencycontroller
{
    public List<skill__c> skilllist{get;set;}
    public String Selected{get;set;}
     
     public skillproficiencycontroller()
         {
             skilllist = new List<Skill__c>();
             skilllist= [select Name FROM skill__c];
         }

     public List<selectoption> getitems() {
         List<SelectOption> options = new List<SelectOption>();  
                 options.add(new SelectOption('Basic Knowledge' , 'Basic Knowledge'));  
                 options.add(new SelectOption('Intermediate' , 'Intermediate'));
                 options.add(new SelectOption('Advanced' , 'Advanced'));  
                 return options;
       }
   
   public void Save()
     {
    List<Skill_Details__c >skilldetailslist = new List<Skill_Details__c >();
         for(Skill s: selectedskilllist){
          Skill_Details__c sd = new Skill_Details__c();
           sd.Skill_c = s.Id;
           sd.Proficiency__c = Selectedvalue;
          skilldetailslist.add(sd);
          }
       Insert skilldetailslist;
}
}}

View Screenshot
This image is not available because: You don’t have the privileges to see it, or it has been removed from the system
David9133David9133
User-added image