+ Start a Discussion

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

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

if( wtype == 'Post Category')

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

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

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

<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"/>


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



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.