# Validation error when select option is set programmatically on embedded form

**URL:** <https://community.hubspot.com/t/validation-error-when-select-option-is-set-programmatically-on-embedded-form/99802>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [February 8, 2024, 8:57pm UTC](https://community.hubspot.com/t/validation-error-when-select-option-is-set-programmatically-on-embedded-form/99802 "2024-02-08T20:57:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Johnston](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ryan_johnston/32/11198_2.png) [@Ryan\_Johnston](https://community.hubspot.com/u/Ryan_Johnston)\
**Post date:** [February 8, 2024, 8:57pm UTC](https://community.hubspot.com/t/validation-error-when-select-option-is-set-programmatically-on-embedded-form/99802/1 "2024-02-08T20:57:51Z")

</div>

The issue I have is when the form is submitted. This particular select input is required. And when submitting the form, there is a validation error of “missingSelect”. And the select field resets itselt and no longer has the prefilled value selected. With an inline form error of “Please complete this required field.”

I’ve been able to set the “selected” property for an option on a select input using advice found here: [https://community.hubspot.com/t5/APIs-Integrations/How-to-change-select-option-in-HubSpot-forms-via-…](https://community.hubspot.com/t5/APIs-Integrations/How-to-change-select-option-in-HubSpot-forms-via-a-click-event/m-p/230832#M9728)

This is the code I’m using the programatticaly set an option for a select input

`$('select[name="primary_country"] > option[value="Tonga"]').prop("selected", true).change();`

HTML looks like this:

```lia-code-sample
<select id="primary_country-de3a696a-66ee-46ea-a8e9-0ebc4f65e5c3" required="" class="hs-input is-placeholder" name="primary_country">
 <option disabled="" value="">Select your country</option>
 <option value="Afghanistan">Afghanistan (<U+202B>افغانستان<U+202C>‎)</option>
 <option value="Albania">Albania (Shqipëri)</option>
 <option value="Algeria">Algeria (<U+202B>الجزائر<U+202C>‎)</option> 
 .
 .
 .
</select

```

Any ideas on how to fix this issue?  
Thanks so much for any help you can provide,

Ryan Johnston

---

<div class="post-metadata">

**Author:** ![zach\_threadint](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zach_threadint/32/46318_2.png) [@zach\_threadint](https://community.hubspot.com/u/zach_threadint)\
**Post date:** [February 8, 2024, 9:24pm UTC](https://community.hubspot.com/t/validation-error-when-select-option-is-set-programmatically-on-embedded-form/99802/2 "2024-02-08T21:24:39Z")

</div>

Hi [@Ryan\_Johnston](https://community.hubspot.com/t5/user/viewprofilepage/user-id/682450) 👋

Any chance you can share a link to a sandboxed version of the form in question? Feel free to share privately via DM if you prefer.

Thanks,

Zach

--

---

<div class="post-metadata">

**Author:** ![zach\_threadint](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zach_threadint/32/46318_2.png) [@zach\_threadint](https://community.hubspot.com/u/zach_threadint)\
**Post date:** [February 9, 2024, 6:21am UTC](https://community.hubspot.com/t/validation-error-when-select-option-is-set-programmatically-on-embedded-form/99802/3 "2024-02-09T06:21:02Z")

</div>

Hi [@Ryan\_Johnston](https://community.hubspot.com/t5/user/viewprofilepage/user-id/682450) 👋

Thanks for sharing the test form URL via DM.

I found that the Primary Country form field didn’t reset if it was [auto-populated via the URL query string parameter](https://knowledge.hubspot.com/forms/can-i-auto-populate-form-fields-through-a-query-string) (rather than via jQuery). For example, assuming your form URL was **[https://example.com/form](https://example.com/form)**, you could auto-populate the Primary Country field like this:

[https://example.com/form\*\*?primary\_country=Tonga](https://example.com/form**?primary%5C_country=Tonga)\*\*

Is presetting form fields in this way an option for you?

I hope this proves useful. Please let me know if you have any follow-up questions.
