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
kittu9kittu9 

Hiding and Displaying fields in visual force page based on pick list value using Java script

<apex:page standardController="Template__c" extensions="WidgetController">
<script>
function displayFields()
{
var wtype = document.getElementById('{!$Component.frm1.pblock.pbsection.type}').value;

if( wtype == 'Post Category')
{
alert(wtype);

document.getElementById('{!$Component.frm1.pblock.pbsection.title}').visible = false ;

}
}
</script>
<apex:form id="frm1">
<apex:pageBlock id="pblock">
<apex:pageBlockButtons >

<apex:commandButton value="Save"/>
<apex:commandButton value="Cancel"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Information" collapsible="false" columns="1" id="pbsection">
<apex:inputField value="{!tmptWidget.Type__c}" id="type" onchange="displayFields();"/>
<apex:inputField value="{!tmptWidget.Page__c}" id="template"/>
<apex:inputField value="{!tmptWidget.Title__c}" id="title"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Here Type__c is picklist based on pick list selected value want to visible one field in vf page and remaining other field want to hide how we can do it through java script. Please give inputs for this. I did like above but not working. pls let me know wht mistake i done in above code

Puja_mfsiPuja_mfsi

Hi,

you need to change in your java script :

document.getElementById('{!$Component.frm1.pblock.pbsection.title}').style.visibility = 'hidden';

 

why r u not use rendered attribute for this?

 

Please let me know if u have any problem on same and if this post helps u plz give KUDOS by click on star at left.