# Append "checked" checkbox values to form textarea

**URL:** <https://community.hubspot.com/t/append-checked-checkbox-values-to-form-textarea/125421>\
**Category:** CMS Development\
**Created:** [February 4, 2025, 10:14pm UTC](https://community.hubspot.com/t/append-checked-checkbox-values-to-form-textarea/125421 "2025-02-04T22:14:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmcmillan99](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tmcmillan99/32/93181_2.png) [@tmcmillan99](https://community.hubspot.com/u/tmcmillan99)\
**Post date:** [February 4, 2025, 10:14pm UTC](https://community.hubspot.com/t/append-checked-checkbox-values-to-form-textarea/125421/1 "2025-02-04T22:14:51Z")

</div>

I have a page that contains numerous checkboxes and a form. I am trying to append the values of the checkboxed that have been checked to the form’s textarea. I have not been able to get it to work and do not know what I am missing. Here is my javascript&colon;

```lia-code-sample
<script>
 // Request Training
function captureCheckboxValues() {
 const checkboxes = document.querySelectorAll('input[type="checkbox"]:checked');
 const checkedValues = [];
 checkboxes.forEach(checkbox => {
 checkedValues.push(checkbox.value);
 });
 const textarea = document.getElementByClassName('hs-fieldtype-textarea');
 textarea.value = checkedValues.join('\n');
}
</script>

```

Do I have something wrong with my code? Or is there something special required due to it being Hubspot form? Any suggestions/recommendations would be greatly appreciated.

Thanks,

Terry McMillan

---

<div class="post-metadata">

**Author:** ![GRajput](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/grajput/32/102020_2.png) [@GRajput](https://community.hubspot.com/u/GRajput)\
**Post date:** [February 5, 2025, 7:37am UTC](https://community.hubspot.com/t/append-checked-checkbox-values-to-form-textarea/125421/2 "2025-02-05T07:37:22Z")

</div>

Hi @tmcmillan99

Your function is correct and it should work for simple HTML form. But I assume you are trying to do this in a HubSpot form and for that, you need to use form callback functions. This [**doc**](https://developers.hubspot.com/docs/reference/cms/forms#embed-code-callbacks) will help you with that. Here is also an example:

```lia-code-sample
<script>
 hbspt.forms.create({
 portalId: '',
 formId: '',
 onFormReady: function ($form) {
 // Request Training
 function captureCheckboxValues() {
 const checkboxes = document.querySelectorAll('input[type="checkbox"]:checked');
 const checkedValues = [];
 checkboxes.forEach(checkbox => {
 checkedValues.push(checkbox.value);
 });
 const textarea = document.getElementByClassName('hs-fieldtype-textarea');
 textarea.value = checkedValues.join('\n');
 }
 },
 });
</script>

```

I hope this will help you out. Please mark it as **Solution Accepted and upvote** to help another Community member.  
Thanks!

---

<div class="post-metadata">

**Author:** ![tmcmillan99](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tmcmillan99/32/93181_2.png) [@tmcmillan99](https://community.hubspot.com/u/tmcmillan99)\
**Post date:** [February 5, 2025, 2:41pm UTC](https://community.hubspot.com/t/append-checked-checkbox-values-to-form-textarea/125421/3 "2025-02-05T14:41:43Z")

</div>

@GRajput Awesome! Thanks for the additional information and clarification. Exactly what I needed. I had a feeling that I was missing something in regards to it being a Hubspot form.
