In Salesforce, how to access Visualforce components values into a JavaScript?

0 votes
84 views
Sylvester Balchunas asked 09-Feb-2018 in SalesForce by Sylvester Balchunas

In Salesforce, how to access Visualforce components values into a JavaScript?

1 Answer

0 votes
Tarun Gautam answered 09-Feb-2018 by Tarun Gautam
In Salesforce using the Component Global Variable, we can access the visualforce components in JavaScript. For example: if you want to use an ID of an Apex field with ID = “afield”.

So that, you can use it like this:
Syntax: {!$Component.afield}

The above syntax uses properties of the field in the javascript. Take an example: 
You are going to store the field’s values in javascript, then the code will display like this:
<script>

 Var a = 'document.getElementById('{!$component.afield}').value';
</script>