# Assign Reference field to a dropdown

**URL:** <https://forum.wixstudio.com/t/assign-reference-field-to-a-dropdown/54734>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [December 20, 2023, 1:52am UTC](https://forum.wixstudio.com/t/assign-reference-field-to-a-dropdown/54734 "2023-12-20T01:52:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris2242](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@Chris2242](https://forum.wixstudio.com/u/Chris2242)\
**Post date:** [December 20, 2023, 1:52am UTC](https://forum.wixstudio.com/t/assign-reference-field-to-a-dropdown/54734/1 "2023-12-20T01:52:52Z")

</div>

Hello there!

I’m looking to assign a collection field of type “Reference” to a dropdown.

The ID of the reference field is 46b40fc8-f433-45ce-aa0a-6c85b7c22bc2

After getting the item, I try to assign the reference value to a dropdown.

Item from collection

```js
{
  "description": "This is a description.",
  "_id": "4d37819d-c259-4ed6-a5bc-d12d7654e9b2",
  "_owner": "bf9f633d-e83d-47ba-b206-08090cfc681e",
  "_createdDate": "Fri Nov 24 2023 12:33:51 GMT-0500 (Eastern Standard Time)",
  "_updatedDate": "Tue Dec 19 2023 17:00:14 GMT-0500 (Eastern Standard Time)",
  "sub-category": "3233922d-c754-46d5-863b-9035403333cd",

}

```

If I do it like that, my item is getting selected correctly:  
**$w(‘#sub-category’).value = “3233922d-c754-46d5-863b-9035403333cd” // working**

If I assign the dropdown directly from the collection, my item is not selected.  
**$w(‘#sub-category’).value = String(item.sub-category); // Not working**

And Yes, my dropdown is getting populated with all the sub-categories.

What am I doing wrong?

Thanks!

---

<div class="post-metadata">

**Author:** ![anthony](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/anthony/32/79536_2.png) [@anthony](https://forum.wixstudio.com/u/anthony)\
**Post date:** [December 20, 2023, 5:40pm UTC](https://forum.wixstudio.com/t/assign-reference-field-to-a-dropdown/54734/2 "2023-12-20T17:40:00Z")

</div>

> [@Chris2242](#):
>
> $w(‘#sub-category’).value = String(item.category); // Not working

This line is referencing `item.category` rather than `item.sub-category`. Worth noting that dashes are not allowed in variable names in Javascript so there’s no way to reference `item.sub-category` but you could rename it and reference `item.subCategory`. If this item is coming from a content collection it won’t allow names with dashes anyways.

Also the `string` primitive (ex. “my string”) and `String` object are not the same in Javascript: [What is the difference between string primitives and String objects in JavaScript? - Stack Overflow](https://stackoverflow.com/questions/17256182/what-is-the-difference-between-string-primitives-and-string-objects-in-javascrip) not sure if that’s your issue but it’s worth considering.

---

<div class="post-metadata">

**Author:** ![Chris2242](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@Chris2242](https://forum.wixstudio.com/u/Chris2242)\
**Post date:** [December 20, 2023, 8:07pm UTC](https://forum.wixstudio.com/t/assign-reference-field-to-a-dropdown/54734/3 "2023-12-20T20:07:57Z")

</div>

Looks like I’ll go and review the naming convention. It turns out that sub-category was not acceptable, so subCategory is working just fine.

Thanks Antony
