You need to sign in to do that
Don't have an account?
dave23
Javascript and Visualforce field Ids
I have some javascript code that runs to popup a window with account details as follows. The code needs to get the selected index which is the ID of the account to display.
I have not been able to find a way to reference the selectedIndex other than hardcoding the Id generated by Salesforce. Obviously this is not a good method as the field Id will probably change at some point. I'm not a JS expert but I would think there is a better way to do this? Can anyone help?
Code:
<script type="text/javascript"> function viewAccount() { var acc_select = document.getElementById('j_id0:convertData:j_id4:j_id8:accountName'); var acc_id = acc_select.options[acc_select.selectedIndex].value; if (acc_id == null || acc_id == "" || acc_id == 000000000000000) { alert("You can only view existing accounts."); } else { var AccountWindow = window.open('/' + acc_id + '/p','Account','height=300,width=500,status=yes,scrollbars=yes,resizable=yes'); AccountWindow.focus(); } } </script>
VF code:
<apex:panelGroup >
<apex:selectList id="accountName" required="true" size="1" value="{!selectedAccountID}">
<apex:selectOptions value="{!leadAccountNames}"/>
</apex:selectList>
<apex:outputLabel value="View" title="View (New Window)" onclick="viewAccount()" id="theLink"></apex:outputLabel>
</apex:panelGroup>
Thanks
Dave
See docs on how to use $Component, there is an example in this article where i use $Component to get the ID of a field generated by a third party JS library.
http://blog.sforce.com/sforce/2008/12/forcecom-sites-and-captcha.html
and
http://wiki.apexdevnet.com/index.php/Sites_And_Captcha
here is what I did:
then modify your JS function to take a string passed in for the element name
All Answers
See docs on how to use $Component, there is an example in this article where i use $Component to get the ID of a field generated by a third party JS library.
http://blog.sforce.com/sforce/2008/12/forcecom-sites-and-captcha.html
and
http://wiki.apexdevnet.com/index.php/Sites_And_Captcha
here is what I did:
then modify your JS function to take a string passed in for the element name
Thanks Ron. That did the job.
Dave