---
title: "In Salesforce, how to access Visualforce components values into a JavaScript?"  
description: "In Salesforce, how to access Visualforce components values into a JavaScript?"  
author: "Sylvester Balchunas"  
published: 2018-02-09  
canonical: https://answers.mindstick.com/qa/34267/in-salesforce-how-to-access-visualforce-components-values-into-a-javascript  
category: "salesforce"  
tags: ["salesforce", "javascript", "visualforce components"]  
reading_time: 1 minute  

---

# In Salesforce, how to access Visualforce components values into a JavaScript?

In [Salesforce](https://yourviews.mindstick.com/view/82645/what-you-need-to-know-to-get-started-on-salesforce-field-service), how to [access](https://yourviews.mindstick.com/view/81917/what-is-mobile-cloning-technology-which-gives-access-to-whatsapp-chats) Visualforce [components](https://www.mindstick.com/blog/74096/understanding-the-role-of-some-integral-ac-components) [values](https://www.mindstick.com/forum/327/sum-textbox-values) into a [JavaScript](https://www.mindstick.com/forum/34618/javascript-array-function)?

## Answers

### Answer 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>
```


---

Original Source: https://answers.mindstick.com/qa/34267/in-salesforce-how-to-access-visualforce-components-values-into-a-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
