+ Start a Discussion
Jonny SimmoJonny Simmo 

Using Visualforce Apex component values in Javascript

Hello all,

I have been struggling to access the values of VF apex component values within a Javascript function, I cant understand why it is not working? I have been trying this for hours and have read various blogs on the web but the usual methods which I keep reading do not work?

Surely this is an easy thing to do, can you see what I am doing wrong?

// An example of the type of grid I have...
<apex:form id="form1">
  <apex:panelGrid columns="1" id="grid1" style="margin-top:1em;">
     <apex:inputTextarea id="inputText5" value="{!inputText5}" cols="25" rows="6"/>
     <apex:commandButton action="{!submit}" value="Submit" onClick="Testval();"/>
   </apex:panelGrid>
</apex:form>

// An example of the Javascript and how I am accessing it...
function Testval() {
   alert('Inside Testval() method');
   var inputText5 = document.getElementById('{!$Component.form1.grid1.inputText5}').value;
   alert("inputText5 = " + inputText5);



 
BalajiRanganathanBalajiRanganathan
Do not use the id of Panel Grid to get the input Text Area. 

use simply {!$Component.form1.inputText5}
Jonny SimmoJonny Simmo
Thanks for the reply.

I have tried doing that but when I display the value in an alert message it comes back as undefined?