# Retrieve select value from form

**URL:** <https://community.hubspot.com/t/retrieve-select-value-from-form/28262>\
**Category:** CMS Development\
**Tags:** events, forms\
**Created:** [November 20, 2020, 8:42am UTC](https://community.hubspot.com/t/retrieve-select-value-from-form/28262 "2020-11-20T08:42:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [November 20, 2020, 8:42am UTC](https://community.hubspot.com/t/retrieve-select-value-from-form/28262/1 "2020-11-20T08:42:25Z")

</div>

Hi guys,

I’m trying to create a cookie to store a value from a select form field - I’v been trying different options but unsuccessful eveytime 😥 - can someone please help me?

The Hubspot form in question can be located: [Document collaboration solutions for real-time teamwork](https://www.huddle.com/get-started)

**The select field is :** Comapany Size

**The value I’m trying to target is the first option:** 1-10

**This is my code:**

\<script\>

var formField = document.querySelector(‘form["name=“size\_of\_organisation\_\_c”]’).value;

var formValue = “1-10”;

var cookieName = sizeOfOrg;

var cookieValue = smb;

if (formField == formValue) {

document.cookie = “cookieName=cookieValue”;

}

\</script\>

Any help would be much appreciated

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [November 23, 2020, 6:38pm UTC](https://community.hubspot.com/t/retrieve-select-value-from-form/28262/2 "2020-11-23T18:38:14Z")

</div>

Hi @Anonymous

Unsure if you are still working on this, but wanted hook you up with some smart people that can help

@tjoyce , @Gonzalo , @BarryGrennan can you all lend a hand?

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [November 30, 2020, 8:55am UTC](https://community.hubspot.com/t/retrieve-select-value-from-form/28262/3 "2020-11-30T08:55:58Z")

</div>

Thank you so much for you assistance @dennisedson 🙌

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [November 24, 2020, 8:59am UTC](https://community.hubspot.com/t/retrieve-select-value-from-form/28262/4 "2020-11-24T08:59:35Z")

</div>

@Anonymous - I personally would use localStorage instead of a cookie… easier to read and write

Also, you need to use the global javascript events for forms so you can run your code when the user submits the form

```lia-code-sample
window.addEventListener('message', event => {
 if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
 if($('[name="size_of_organisation__c"]').length){
 localStorage.setItem('organization-size', $('[name="size_of_organisation__c"]').val());
 }
 }
});

```

Then you can retrieve the stored item with

```lia-code-sample
var orgSize = localStorage.getItem('organization-size');
console.log(orgSize)

```

* * *

If this answer helped, please, mark as solved 😄

* * *

[tim@belch.io](mailto:tim@belch.io) | [forms.belch.io](https://forms.belch.io) | Design your own Beautiful HubSpot Forms; No coding necessary.

Drop by and say Hi to me [on slack](http://slack.belch.io/).

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [November 30, 2020, 8:57am UTC](https://community.hubspot.com/t/retrieve-select-value-from-form/28262/5 "2020-11-30T08:57:48Z")

</div>

@tjoyce you are a legend! Thank you so much! I really appreciate the help 🙏

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [November 30, 2020, 3:34pm UTC](https://community.hubspot.com/t/retrieve-select-value-from-form/28262/6 "2020-11-30T15:34:51Z")

</div>

don’t let it go to your head, @tjoyce 😜

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [November 30, 2020, 3:51pm UTC](https://community.hubspot.com/t/retrieve-select-value-from-form/28262/7 "2020-11-30T15:51:20Z")

</div>

Too late @dennisedson 😄
