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
vinayk kumarvinayk kumar 

hi guys ,i want to insert radiobutton value in customobject from vf page using javascript,i have tried but it inserted only textboxes(name ,email),radio selected option doesnot insertd.

want insert selected radio option from vf page
<apex:page controller="OnlineFeed" id="testpage">
    <apex:form id="theform" >
        <apex:pageBlock title="OnlineFeedback" id="pb">
            <apex:pageBlockSection columns="1" title="RegistrationForm" collapsible="false" >
                <apex:pageBlockSectionItem id="pbsi1">
                    <apex:outputLabel >Name:</apex:outputLabel>
                    <apex:inputText value="{!TName}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem id="pbsi2">
                    <apex:outputLabel >Email:</apex:outputLabel>
                    <apex:inputText value="{!TEmail}" />
                    
                </apex:pageBlockSectionItem> 
            </apex:pageBlockSection>
            <apex:outputLabel >How satisfied were you with:</apex:outputLabel><br/>
            <h1>Key point #1</h1><br/>
            
            
            <input class="radioBtn" type="radio" name="order" onchange="getSelectedValue()" value="Very Satisfied"/>Very Satisfied
            <input class="radioBtn" type="radio" name="order" onchange="getSelectedValue()" value="Satisfied" />Satisfied
            <input class="radioBtn" type="radio" name="order" onchange="getSelectedValue()" value="Neutral" />Neutral
            <input class="radioBtn" type="radio" name="order" onchange="getSelectedValue()" value="Unsatisfied" />Unsatisfied
            <input class="radioBtn" type="radio" name="order" onchange="getSelectedValue()" value="veryUnsatisfied" />veryUnsatisfied<br/>
            
            <apex:outputLabel >Feel free to add any other comments or suggestions:</apex:outputLabel><br/>
            <apex:inputTextarea cols="30" rows="10"/><br/>
            <apex:outputText >* The information given within the Feedback Form will be used for service improvement only and are strictly confidential.</apex:outputText>
            
            
            
            <apex:commandButton title="save" onclick="getSelectedValue();" action="{!submitted}" value="save" >
              
                
            </apex:commandButton>
        
        </apex:pageBlock>
     
        
    </apex:form>
    <script>
    
    function getSelectedValue() {
        var radioBtns = document.getElementsByClassName("radioBtn");
        for(var i = 0; i < radioBtns.length; i++){
            if(radioBtns[i].checked)   
            {
                alert( 'button checked :'+radioBtns[i].value);
                document.getElementById("key1").value =radioBtns[i].value; 
                
                alert( 'button checked :'+radioBtns[i].value);
                document.getElementById("key2").value=radioBtns[i].value;
                alert( 'button checked :'+radioBtns[i].value);
                document.getElementById("key3").value=radioBtns[i].value;
                alert('button checked:'+radioBtns[i].value);
                document.getElementById("key4").value=radioBtns[i].value;
                alert('button checked:'+radioBtns[i].value);
                document.getElementById("key5").value=radioBtns[i].value;
                alert('button checked:'+radioBtns[i].value);
                var key1=radiBtns[i].value;
                return false ;
            }
            
                
        }
    }
        </script>
</apex:page>






public class OnlineFeed {
    public string TName{set;get;}
    public string TEmail{set;get;}
    public string  key1 {set;get;}
    //public string getSelectedValue{set;get;}
    public string key2{set;get;}
    public string key3{set;get;}
    public string key4{set;get;}
    public string key5{set;get;}
    
   public OnlineFeed(){
        
        TName='';
        TEmail='';
        key1= ''; 
        key2='';
        key3='';
        key4='';
        key5='';
        
    }
    
    public void submitted(){
        RegistrationForm__c r=new RegistrationForm__c();
        r.Name = TName;
        r.Email__c=TEmail;
        r.Key_point_1__c=key1;
        r.Key_point_2__c=key2;
        r.Key_point_3__c=key3;
        r.Key_point_4__c=key4;
        r.Key_point_5__c=key5;
        insert r;
        
        
    }
    

}
VivekShindeVivekShinde
Hi Vinayak,

You might want to go through the visuaforce developer guide to check how the radio button are displayed on the visualforce page. Below is the link for the same:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectRadio.htm

For your 3 key points you can create 3 lists of the SelectOption and bind on the vf page. You will then need to bind 3 string variables to apex:selectRadio vf tags, you can use your existing key1, key2 and key3 variables for this.

When a radio button will be selected from the groups Keypoint#1, Keypoint#2 or Keypoint#3, the respective values will be set in the string variables, key1, key2 and key3 in the controller. It will not be required to call a javascript metod to set the values. The value of the selected radio option will be available in the action method called on the submit button.