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
SimrinSimrin 

SelectRadio not working properly with actionListener

Hello,

I am calling action Function from selectRadio but it is not getting caled.
It works perfectly if i replace selectRadio with selectList.

Why the behaviour is difference for Radio button.
<script type="text/javascript">    
	function initJSChoice(id1){ 
		initColumn(document.getElementById(id1).value);
	}
	</script> 

<apex:form id="map">
        <apex:actionFunction name="initColumn" action="{!matrix}" reRender="map,search">
            <apex:param name="param1" value="" />
        </apex:actionFunction>
	<apex:selectRadio value="{!choice}" id="contentForDisplay"  onchange="initJSChoice('{!$Component.contentForDisplay}');" >
            <apex:selectOption itemLabel="a" itemValue="a"/>
            <apex:selectOption itemLabel="b" itemValue="b"/>
            <apex:selectOption itemLabel="c" itemValue="c"/>
        </apex:selectRadio>  
</apex:form>

 
Best Answer chosen by Simrin
ManojjenaManojjena
Hi Simrin ,
What actually you want to pass through param ? If you want to pass the select option value  you can get from choice varibale which is already available in your class .
You can try with the code I have posted above and just change the debug statement like below .
System.debug('********************'+choice);

Thnaks
Manoj

All Answers

ManojjenaManojjena
Hi Simrin ,

Try to change the event to onSelect it will help .

 
SimrinSimrin
onSelect doesnot even cal the javascript.

I also tried immediate="true" but that didnt work out too 
ManojjenaManojjena
Hi Simrin ,
I have tried with a small POC with your code it is working fro me .I have checked the debug log .
Please have a try with below code it is working .
 
<apex:page controller="RadioPOC">
	<script type="text/javascript">    
		function initJSChoice(id1){ 
			initColumn(document.getElementById(id1).value);
		}
	</script> 
    <apex:form id="map">
		<apex:actionFunction name="initColumn" action="{!matrix}" reRender="map,search">
			<apex:param name="param1" value="" />
		</apex:actionFunction>
		<apex:selectRadio value="{!choice}" id="contentForDisplay"  onchange="initJSChoice('{!$Component.contentForDisplay}');" >
			<apex:selectOption itemLabel="a" itemValue="a"/>
			<apex:selectOption itemLabel="b" itemValue="b"/>
			<apex:selectOption itemLabel="c" itemValue="c"/>
		</apex:selectRadio>  
	</apex:form>
</apex:page>

public class RadioPOC {
    public String choice { get; set; }
    public PageReference matrix() {
         System.debug('********************action function');
         return null;
    }
}
Thanks
Manoj

 
SimrinSimrin
It is giving me same result as before.
 
function initJSChoice(id1){ 
                       alert(id1) //some value
                       alert(document.getElementById(id1)) //some HTML object
                       alert(document.getElementById(id1).value) //undefined
			initColumn(document.getElementById(id1).value);
		}

as the document.getElementById(id1).value is undefined then the actionfuntion is not getting called and hence the controller function not getting called.
 
ManojjenaManojjena
Hi Simrin ,
What actually you want to pass through param ? If you want to pass the select option value  you can get from choice varibale which is already available in your class .
You can try with the code I have posted above and just change the debug statement like below .
System.debug('********************'+choice);

Thnaks
Manoj
This was selected as the best answer