You need to sign in to do that
Don't have an account?
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: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
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
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: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.
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.
use script tag below the input field
<script> var Rank = document.getElementById('{!$Component.Rank}'); </script>
then you can use Rank in your javascript.