Activity › Forums › Salesforce® Discussions › Accessing Visualforce Components values into a Javascript
-
Accessing Visualforce Components values into a Javascript
Posted by Anurag algoworks on September 13, 2018 at 1:14 PMHow can we access Visualforce Components values into a Javascript?
Parul replied 7 years, 9 months ago 5 Members · 4 Replies -
4 Replies
-
Hi Anurag,
Just add an ID to your apex:inputField and then access it in javascript using:
var abc= document.getElementById(“input_abc”);
You can then access your value using:
abc.value
Hope this helps.
- [adinserter block='9']
-
Hi,
Using Component global variable, we can access visualforce components in javascript. Let us suppose, we want to use id of an apex field with id=”afield”. So, we can use the {!$Component.afield} syntax to use properties of the field in javascript.
Thanks
-
Hello Anurag,
I think you have to use document.getElementById(‘{!$Component.LabelName}’) to access visualforce components values into a JavaScript.
Thanks.
-
JavaScript provides the framework for communicating between other JavaScript objects, HTML elements, and the Visualforce controller.
JavaScript code can be written in a Visualforce page and can be included in a Visualforce page by using a static resource. This is the best method to use to include a JavaScript library in a Visualforce page. We can use the <apex:includeScript>component to include a JavaScript library from static resources.
For example:
<apex:includeScript value=”{!$Resource.MyJSFile}”/>
Thanks
Log In to reply.