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
SARANG DESHPANDESARANG DESHPANDE 

On change event in visualforce

I am new to visualforce and I want to display a lookup field when certain value in one of dropdowns changes on a custom object detail page.All other times the lookup field should not be visible.
How can this be achieved with visualforce?
Which tags would be required?
And would need to overwrite current detail page or we can edit the current detail page?
James LoghryJames Loghry
You would need to override the current detail page. The reason being is you would need a javascript hack to implement such functionality on the detail page of a record.  Javascript hacks are not only unsupported and likely to break in future releases, but the platform team has taken away all the ways (I've know of) to hack the detail page.

To achieve the functionality you're looking for, you'd use the apex:actionSupport tag (as one possiblity) and the rerender tag to rerender the parent element of your lookup field.  I've providing a really simple example below of what your VF markup might look like. 

If you do go the route of overriding the detail with with Visualforce, one thing you'll want to consider is using a field set for easily configuring the fields that are displayed on the page.
 
<apex:form id="myform">

    <apex:inputField value="{!MyCustomObject__c.Lookup__c}" rendered="{!IF(ISBLANK(MyCustomObject__c.Dropdown__c),false,true)}">

    <apex:inputField value="{!MyCustomObject__c.Dropdown__c}">
        <apex:actionSupport event="onchange" rerender="myform"/>
    </apex:inputField>
</apex:form>

Hope that helps.