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
NikeNike 

Call multi picklist in Vforce page using script


I have created visual force page using standard controller, In that I have a multipicklist and this should reflect the value based upon the recordtype in contact sobject. I know there are no such options in Vforce page. so i tried hardcoding the value using javascript but Iam not able to call the multiselect picklist in the script function.

Please give your suggestion.

 

Vforce Page: <apex:page standardController="Contact"> <apex:form > <apex:pageBlock title="Try" mode="Edit"> <apex:pageBlockSection title="Try It Again "> <apex:pageBlockSectionItem id="sec_Rank"> <apex:outputLabel >Rank</apex:outputLabel> <apex:inputField value="{!Contact.Rank__c}" id="Rank" onchange="javascript&colon;change()"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <script language='JavaScript'> change(); function change() { try{ alert('{!$Component.Rank}'); }catch(e);{alert(e);} } </script> </apex:page>

 Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
AdyAdy

use script tag below the input field

 

<script> var Rank = document.getElementById('{!$Component.Rank}'); </script>

 

 

then you can use Rank in your javascript.

All Answers

Richie DRichie D

Hi,

 

Something like this might help you out. (Not checked the syntax though.)

 

 

<apex:page standardController="Contact"> <apex:form > <apex:pageBlock title="Try" mode="Edit"> <apex:pageBlockSection title="Try It Again "> <apex:pageBlockSectionItem id="sec_Rank"> <apex:outputLabel >Rank</apex:outputLabel> <apex:inputField value="{!Contact.Rank__c}" id="Rank" onchange="javascript&colon;change(this.value)"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <script language='JavaScript'> change('{!$Component.Rank}'); function change(val) { try{ alert(val'); }catch(e);{alert(e);} } </script> </apex:page>

 Just pass the value of the html element into your JS function.

R. 

 

NikeNike

Thanks,

I have tried but I'm getting an error: Can't move focus to control because it is invisiable, not enabled, or of a type that does not accept the focus.

AdyAdy

use script tag below the input field

 

<script> var Rank = document.getElementById('{!$Component.Rank}'); </script>

 

 

then you can use Rank in your javascript.

This was selected as the best answer