+ Start a Discussion
yvk431yvk431 

how to make a lookup field readonly

Hi all,

 

I have a lookup field inside a repeater on a visual force page . I need to make it a read only field .

 

Can any oe tell me how i can achieve this using javascrpt

 

I tried using the script tag 

<script>

document.getElementById('page:form:pbs:fieldnm').disabled = true.

</script>

 

But as since it was inside a repeater the id of the field is generated as 'page:form:pbs:firs:0:fieldnm'

so how to make readonly for all the items in the list .

 

Also , the lookup field consists of somany ids such as _lkid , _lkold which id we need to conisder. Please help me out

Best Answer chosen by Admin (Salesforce Developers) 
yvk431yvk431

Atlast got it, used a span tag as a container to the lookup inputfield and set its display to none using javascript

 

<script type="text/javascript">
window.onload=function(){
 var spans = document.getElementsByTagName('span');
for(var i=0;i<spans.length;i++)
            {
                if(spans[i].id == 'EUsr')
                spans[i].style.display = "none";
            }   
}

</script>

 

All Answers

jwetzlerjwetzler

Why do you need to do this in javascript? Why not just use outputField?

yvk431yvk431

because i need to use another lookup which is having filter with criteria dependant on this field value. If I am making this field as read only with fls or field type other than "inputField" the dependant lookup is not working.

yvk431yvk431

sorry it worked out great , but only after the record is inserted. while inserting,  the lookup filter is not displaying the values

Please suggest.

 

yvk431yvk431

Atlast got it, used a span tag as a container to the lookup inputfield and set its display to none using javascript

 

<script type="text/javascript">
window.onload=function(){
 var spans = document.getElementsByTagName('span');
for(var i=0;i<spans.length;i++)
            {
                if(spans[i].id == 'EUsr')
                spans[i].style.display = "none";
            }   
}

</script>

 

This was selected as the best answer