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

Getting value of field in java script



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 -->
function copyToClipid(textid)
var copy_id= document.getElementById(textid).value;
window.prompt ("Copy to clipboard: Ctrl+C, Enter", copy_id);

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

  <!-- End Default Content REMOVE THIS -->


Best Answer chosen by Admin (Salesforce Developers) 


     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.