+ Start a Discussion

'Hidden' span area redisplayed after validation fail on form submit

I have a VF page working that hides certain sections of the page depending upon the users selection via radio buttons.



<apex:selectRadio value="{!Custom_object__c.Custom_field__c}" onclick="display(this);" >


<span id="Details" style="display: block">
function display(x) {
var display = x;
if (display == 'true') {
	document.getElementById('Details').style.display = 'none';
} else {
	document.getElementById('Details').style.display = 'block';


The display(this) function sets the style of the span section to be either none or block depending upon the radio button selection.


This all works fine except that when the user would push the Submit button on the form, if there is a field validation error, then the page is re-loaded and any of the changes made to the span section's visibility are reset to their default values.


I've tried trapping this with the window.onload handler, but of course any global variables I might set have been reset along with the page load. Also if I try to query the value of the radio button component, it's value is not available via the onload handler.



You can set the value from Apex Class. Refer the sample code provded below :


//In VF page

<DIV ID="DIV_ERR_EVENT" STYLE="DISPLAY:{!getDisplayState};">

<h4 style="text-align:left;">Registration for Event</h4>



// In Apex Class

public String strStatus1='';

public String getDisplayState()


   Event  objEvt= [select id, name, Status__c from Event e where id= :getid()];      


   if(objEvt.Status__c != 'Active')

                        this. strStatus1='block';  


           this. strStatus1='none';       


   return this. strStatus1;



Hope this helps.