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
shreekanthshreekanth 

i want to store radio buton value which i selected and as wel as associated question also

Hi,

  the following is my example.......problem is " when i click radio button i want to store radio buton value which i selected and as wel as associated question also".....and i got how to store radio button value when i click,but i did n't get the associated question........ please help me on this.

 

Question : Who was the developer of 'C' language

Bjarne Stroustrup
James Gosling

Dennis Ritchie

Best Answer chosen by Admin (Salesforce Developers) 
harsha__charsha__c

Hey I just did one modification.This should work..!

 

<apex:page standardController="Questions__c" recordSetVar="qtns" extensions="verifyexam">
<script>
     function check(t1)
     {
       paraFunction(t1.value, t1.parentNode.parentNode.parentNode.parentNode.previousSibling.innerHTML);
     }//check
</script>

<apex:form id="form1">
      <apex:dataList var="q" value="{!qtns}" type="1" >
        <apex:pageBlock id="block1">
             <output type="text" id="qstn">{!q.Question__c}</output>           


<apex:selectRadio layout="pageDirection" id="r2" onclick="check(this)">
<apex:selectOption itemValue="{!q.Option1__c}" itemLabel="{!q.Option1__c}" />
<apex:selectOption itemValue="{!q.Option2__c}" itemLabel="{!q.Option2__c}" />
<apex:selectOption itemValue="{!q.Option3__c}" itemLabel="{!q.Option3__c}" />
</apex:selectRadio>
          </apex:pageBlock>
      </apex:dataList>
       <apex:actionFunction name="paraFunction" action="{!addValues}" rerender="view">       
         <apex:param id="aname" name="radiovalues" value="" />
         <apex:param id="qname" name="radiovalues" value="" />  
       </apex:actionFunction>
   <apex:commandButton value="Finish" action="{!finish}" />
   </apex:form>
   </apex:page>

 My change is here

paraFunction(t1.value, t1.parentNode.parentNode.parentNode.parentNode.previousSibling.innerHTML);

All Answers

harsha__charsha__c

Hi 

 

For suggetions on this may need to see it's page markup..!

 

If it is possible can you paste it over here

 

shreekanthshreekanth

Hi harsha,

 

<apex:page standardController="Questions__c" recordSetVar="qtns" extensions="verifyexam">
<script>
     function check(t1)
     {
       paraFunction(t1.value);
     }//check
</script>

<apex:form id="form1"> <apex:dataList var="q" value="{!qtns}" type="1" > <apex:pageBlock id="block1"> <apex:outputText value="{!q.Question__c}" /> <apex:selectRadio layout="pageDirection" id="r2" onclick="check(this)"> <apex:selectOption itemValue="{!q.Option1__c}" itemLabel="{!q.Option1__c}" /> <apex:selectOption itemValue="{!q.Option2__c}" itemLabel="{!q.Option2__c}" /> <apex:selectOption itemValue="{!q.Option3__c}" itemLabel="{!q.Option3__c}" /> </apex:selectRadio> </apex:pageBlock> </apex:dataList> <apex:actionFunction name="paraFunction" action="{!addValues}" rerender="view"> <apex:param id="aname" name="radiovalues" value="" /> </apex:actionFunction> <apex:commandButton value="Finish" action="{!finish}" /> </apex:form> </apex:page>

 the above code is my VF page


        i can store radio button value but am unable to store question............please help me on this

harsha__charsha__c

Hey shreekanth

 

try this now..!

 

<apex:page standardController="Questions__c" recordSetVar="qtns" extensions="verifyexam">
<script>
     function check(t1)
     {
       paraFunction(t1.value, t1.parentNode.parentNode.parentNode.parentNode.innerHTML);
     }//check
</script>

<apex:form id="form1">
      <apex:dataList var="q" value="{!qtns}" type="1" >
        <apex:pageBlock id="block1">
             <output type="text" id="qstn">{!q.Question__c}</output>           
<apex:selectRadio layout="pageDirection" id="r2" onclick="check(this)"> <apex:selectOption itemValue="{!q.Option1__c}" itemLabel="{!q.Option1__c}" /> <apex:selectOption itemValue="{!q.Option2__c}" itemLabel="{!q.Option2__c}" /> <apex:selectOption itemValue="{!q.Option3__c}" itemLabel="{!q.Option3__c}" /> </apex:selectRadio> </apex:pageBlock> </apex:dataList> <apex:actionFunction name="paraFunction" action="{!addValues}" rerender="view"> <apex:param id="aname" name="radiovalues" value="" /> <apex:param id="qname" name="radiovalues" value="" /> </apex:actionFunction> <apex:commandButton value="Finish" action="{!finish}" /> </apex:form> </apex:page>

 

In this I have added one more param. Recieve it from the controller

 

the below line gives you the question value..!

 

t1.parentNode.parentNode.parentNode.parentNode.innerHTML

 

Let me know if any concerns are there...

 

If this makes your solution, mark it as solution for other's reference..!

 

shreekanthshreekanth

Harsha...i added to my code what you have  written.....then

 

  when i click the radio button "the radio button value is stored into the custom object field..........But here we have some problem that is "question is not stored into object..... instead of question, the following code is stored into the custom object field"

 

<tbody><tr>
<td>
<input name="j_id0:form1:j_id2:0:block1:r2" id="j_id0:form1:j_id2:0:block1:r2:0" value="Apple" onclick="check(this)" type="radio"><label for="j_id0:form1:j_id2:0:block1:r2:0"> Apple</label></td>
	</tr>
	<tr>
<td>
<input name="j_id0:form1:j_id2:0:block1:r2" id="j_id0:form1:j_id2:0:block1:r2:1" value="Bapple" onclick="check(this)" type="radio"><label for="j_id0:form1:j_id2:0:block1:r2:1"> Bapple</label></td>
	</tr>
	<tr>
<td>
<input name="j_id0:form1:j_id2:0:block1:r2" id="j_id0:form1:j_id2:0:block1:r2:2" value="Cat" onclick="check(this)" type="radio"><label for="j_id0:form1:j_id2:0:block1:r2:2"> Cat</label></td>
	</tr>
</tbody>

 the above code is stored into custom object field insted of question..................

 

 

shreekanthshreekanth

is there any other way to store "radio button value and associated question" ????????????.

harsha__charsha__c

Hi

 

Did you use the same page that I sent or changed..?

 

If changed paste your page mark-up here..So that  the error can found out

harsha__charsha__c

Hey I just did one modification.This should work..!

 

<apex:page standardController="Questions__c" recordSetVar="qtns" extensions="verifyexam">
<script>
     function check(t1)
     {
       paraFunction(t1.value, t1.parentNode.parentNode.parentNode.parentNode.previousSibling.innerHTML);
     }//check
</script>

<apex:form id="form1">
      <apex:dataList var="q" value="{!qtns}" type="1" >
        <apex:pageBlock id="block1">
             <output type="text" id="qstn">{!q.Question__c}</output>           


<apex:selectRadio layout="pageDirection" id="r2" onclick="check(this)">
<apex:selectOption itemValue="{!q.Option1__c}" itemLabel="{!q.Option1__c}" />
<apex:selectOption itemValue="{!q.Option2__c}" itemLabel="{!q.Option2__c}" />
<apex:selectOption itemValue="{!q.Option3__c}" itemLabel="{!q.Option3__c}" />
</apex:selectRadio>
          </apex:pageBlock>
      </apex:dataList>
       <apex:actionFunction name="paraFunction" action="{!addValues}" rerender="view">       
         <apex:param id="aname" name="radiovalues" value="" />
         <apex:param id="qname" name="radiovalues" value="" />  
       </apex:actionFunction>
   <apex:commandButton value="Finish" action="{!finish}" />
   </apex:form>
   </apex:page>

 My change is here

paraFunction(t1.value, t1.parentNode.parentNode.parentNode.parentNode.previousSibling.innerHTML);
This was selected as the best answer
shreekanthshreekanth

Thank u so much  harsha for solved my problem with patience........:):)

Vinay Chaturvedi_SFDCVinay Chaturvedi_SFDC
Hi Shreekanth,I have a smilar requirement to implement a quiz,Can you please share the contoller code too .
Thanks in Advance