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
jkcjkc 

Dynamic inputfield value

I have an input field and I want to change its value when the radiobutton value changes.

Here's the code:

<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<script src="/soap/ajax/33.0/connection.js" type="text/javascript"></script>
<script> 
function Change(){
        for (i = 0; i<6; i++)
        {
            var check = document.getElementById("thePage:theForm:theBlock:theSection:rev:" + i).checked;
            if( check == true)
            {
                totalcv += document.getElementById("thePage:theForm:theBlock:theSection:rev:" + i).value;
            }
            
            check = document.getElementById("thePage:theForm:theBlock:theSection:rec:" + i).checked;
            if(check == true)
            {
                totalcv += document.getElementById("thePage:theForm:theBlock:theSection:rec:" + i).value;
            }
       }    
       var avg = totalcv/count;
        document.getElementById("thePage:theForm:theBlock:theSection:avg").value = avg;
    }
</script>  

<apex:selectRadio id="rev" label="Review" value="{!Account.Review__c}" border="1" disabled="true" styleClass="button1" onchange="Change();">
<apex:selectOption itemLabel="Excellent" itemValue="6"/>
<apex:selectOption itemLabel="Very Good" itemValue="5"/>
<apex:selectOption itemLabel="Good" itemValue="4"/>
<apex:selectOption itemLabel="Average" itemValue="3"/>
<apex:selectOption itemLabel="Fair" itemValue="2"/>
<apex:selectOption itemLabel="Poor" itemValue="1"/>
</apex:selectRadio>

<apex:selectRadio id="rec" label="Recommended" value="{!Account.Recommended__c}" border="1" disabled="true" styleClass="button1" onchange="Change();">
<apex:selectOption itemLabel="Very Satisfactory" itemValue="6"/>
<apex:selectOption itemLabel="Satisfactory" itemValue="5"/>
<apex:selectOption itemLabel="Good" itemValue="4"/>
<apex:selectOption itemLabel="Average" itemValue="3"/>
<apex:selectOption itemLabel="Fair" itemValue="2"/>
<apex:selectOption itemLabel="Poor" itemValue="1"/>
</apex:selectRadio>

<apex:inputField value="{!Account.Average__c}" id="avg" label="Average" />

Thanks in advance :)
Sampath KumarSampath Kumar
Hi Jkc,

Please find the sample code below and let me know if you have any queries.
Visualforce page
===============
<apex:page controller="DynamicRadio">
<apex:form > 
      <apex:pageBlock >
          <apex:pageBlockSection columns="1">
              <apex:pageBlockSectionItem >
                  <apex:outputlabel value="Radio Buttons:"/> 
                      <apex:actionRegion >   
                                              <apex:selectRadio value="{!selectedRadio}">
                                    <apex:selectOptions value="{!radioValues}"/>
                                    <apex:actionSupport event="onchange" rerender="pickListValues"/>
                            </apex:selectRadio>
                     </apex:actionRegion>                         
              </apex:pageBlockSectionItem>
              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Pick List Values"/>   
                      <apex:outputPanel id="pickListValues">   
                                          <apex:selectList value="{!selectedPickListValue}" size="1">
                                    <apex:selectOptions value="{!pickListValues}"/>
                                      </apex:selectList>
                                </apex:outputPanel>
              </apex:pageBlockSectionItem> 
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>

Apex Class:
=========
public class DynamicRadio
{
   
    public String selectedRadio{get; set;}

    public String selectedPickListValue{get; set;}

    Public DynamicRadio()
    {   
        selectedRadio= 'PickList 1';
    }

    public List<selectOption> getRadioValues() 
    {
        List<SelectOption> radioNames = new List<SelectOption>();
       
            radioNames.add(new SelectOption('PickList 1','PickList 1'));
            radioNames.add(new SelectOption('PickList 2','PickList 2'));
           
        return radioNames;
     }

     public List<selectOption> getPickListValues() 
     { 
            
            List<SelectOption> ac = new List<SelectOption>();
            if(selectedRadio== 'PickList 1'){
                   ac.add(new SelectOption('PickList 1 - A','PickList 1 - A'));
                   ac.add(new SelectOption('PickList 1 - B','PickList 1 - B'));
            
            }
            else
            {
            ac.add(new SelectOption('PickList 2 - A','PickList 2 - A'));
                   ac.add(new SelectOption('PickList 2 - B','PickList 2 - B'));
            }
            
            return ac;
      }      
}


Please mark this as best answer if it work to make this community clean and re-usable..Try and let me know if it work for you..

Regards
Sampath Kumar Goud
jkcjkc
i need to do this without using apex class. I want to change the value of in this <apex:inputField value="{!Account.Average__c}" id="avg" label="Average" />