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

Using document.getElementById

Iam trying to get the value of the field entered by the user and use that value to show up other fields on the visualforce page. I did below. We have been dynamically pulling the fields on to the visualforce page based on the data in some objects.. so the id's will changed based on the number of fields that display for each record type. So i tried this

  var code = document.getElementById('pageid:codeid:codeparent:1:codechild:0:codeinnerchild:2:thecode').value;

the part where it says codeparent:1, what does that :1 mean?? those values after colon are changing based on the fields diaplyed on the vf page .How can i get the value irrespective of the fields displayed on the vf page??

Mahesh DMahesh D

Please check the below examples:

The following JavaScript method references a component named msgpost in a Visualforce page:
function beforeTextSave() {
    document.getElementById('{!$Component.msgpost}').value = 
    <apex:outputText id="msgpost" value="Emacs"/> is great.
If your component is nested, you might need to use a more complete component path specifier. For example, if your page looks like this:
    <apex:pageBlock id="theBlock">
        <apex:pageBlockSection id="theSection" columns="1">
            <apex:pageBlockSectionItem id="theSectionItem">
                <apex:outputText id="theText">

If it is dynamic then:
<apex:outputPanel layout="block">
	        <label for="checkbox">Click this box to change text font:</label>
	        <input id="checkbox" type="checkbox"
	        function changeFont(input, textid) {
	            if(input.checked) {
	                document.getElementById(textid).style.fontWeight = "bold";
                   else {
	                document.getElementById(textid).style.fontWeight = "normal";

Also go through the below links for more information:

Please do let me know if it helps you.