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
mallikammallikam 

not able to get the field values through $component!!

I am trying to access the inputtext field values in javascript through component but I am having hard time doing this..suppose I want to get the value of the field refered by id=reqname in a javascript function, how can I get it through $Component?

<apex:pageBlock mode="edit" id="thePageBlock"> <apex:pagemessages ></apex:pagemessages> <apex:actionRegion > <apex:pageBlockSection columns="1" id="remail"> <apex:inputText value="{!custObj.Requestor_Name__c}" id="reqname" />

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
wesnoltewesnolte

Hey

 

Just to clarify the above

 

 

<apex:pageBlock mode="edit" id="thePageBlock"> <apex:pagemessages ></apex:pagemessages> <apex:actionRegion > <apex:pageBlockSection columns="1" id="remail"> <apex:inputText value="{!custObj.Requestor_Name__c}" id="reqname" /> <script> var InputValue = document.getElementById('{!$Component.reqname}').value; </script>

 

 A bit more about this can be found in this article.

 

Cheers,

Wes 

 

All Answers

bbrantly1bbrantly1

 

Javascript

 

var InputValue = document.getElementById('{!$Component.reqname}').value;

 

Make sure the javascript and field are in the same form tag.

 

 

 

Message Edited by bbrantly1 on 07-07-2009 06:50 PM
wesnoltewesnolte

Hey

 

Just to clarify the above

 

 

<apex:pageBlock mode="edit" id="thePageBlock"> <apex:pagemessages ></apex:pagemessages> <apex:actionRegion > <apex:pageBlockSection columns="1" id="remail"> <apex:inputText value="{!custObj.Requestor_Name__c}" id="reqname" /> <script> var InputValue = document.getElementById('{!$Component.reqname}').value; </script>

 

 A bit more about this can be found in this article.

 

Cheers,

Wes 

 

This was selected as the best answer
mallikammallikam
that solves the issue, thanks a lot, wes and brantly.