Wednesday 5 August 2015

Disable Lookup field on Visua lforce Page using Java Script

Hi Floks ,

In this post , I am going to demonstrate on how we can Disable lookup field on visual force page using Java script.

In some scenarios , it may requires to disable or enable look up fields based on the conditions on visualforce page.

Here is the sample code to disable in Javascript:

document.getElementById('thePage:theForm:theVCComp:theComp:thepageBlock:pbs1:pbs1Item1:txtAccount').disabled=true;

document.getElementById('thePage:theForm:theVCComp:theComp:thepageBlock:pbs1:pbs1Item1:txtAccount').value = '';

document.getElementById('thePage:theForm:theVCComp:theComp:thepageBlock:pbs1:pbs1Item1:txtAccount').style.background='whitesmoke';   
      
document.getElementById('thePage:theForm:theVCComp:theComp:thepageBlock:pbs1:pbs1Item1:txtAccount_lkwgt').style.visibility = 'hidden'; 

or 

we can pass Id of field and lookup Icon to Js function , below is the sample code:

function ManageLookupfield(inputfieldId,LookupIconId){
    document.getElementById(inputfieldId).disabled=true;
    document.getElementById('inputfieldId).value = '';
    document.getElementById(inputfieldId).style.background='whitesmoke';   
   document.getElementById(LookupIconId).style.visibility = 'hidden'; 
}

Red highlighted code is the Id values for the Infield and Look up icon to disable from Visual force page.

Thank you.

Haribabu Amudalapalli
Certified force.com Advanced Developer

1 comment:

  1. Posting it is very needed because every human being today want this information. Keep it up. Good luck and thanks for posting Salesforce Development Training | Salesforce Development Certification

    ReplyDelete