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
pradyprady 

Getting value of field in java script

Hi,

 

I have aVF page where in i am trying to copy a outputtext value into prompt. The idea is to have an option to copy field values into clipboard.

The issue i am facing is that the value in javascript is coming as undefined.

first alert shows page1:txtaccid

the second alert shows undefined.

 

Any idea what could be the issue

 

<apex:page standardController="Account" sidebar="false" showHeader="false" id="page1">
  <!-- Begin Default Content REMOVE THIS -->
<script>
function copyToClipid(textid)
{
alert(textid);
alert(document.getElementById(textid).value);
var copy_id= document.getElementById(textid).value;
window.prompt ("Copy to clipboard: Ctrl+C, Enter", copy_id);

}
</script>
    
Account :  <apex:outputField value="{!account.id}" id="txtaccid"/> <input type="button" id="copyMe" class="btn" value="Copy to Clipboard" onclick="copyToClipid('{!$Component.txtaccid}');"/><br/>
Account Name : <apex:outputField value="{!account.name}" id="txtaccname"/>

  <!-- End Default Content REMOVE THIS -->
</apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

     You can use document.getElementById(textid).innerHTML to get the account id from visual force component.


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.