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

Asked 09-Feb-2018
Viewed 957 times

1 Answer


0

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>