Skip to main content
Level 2
Dec 3, 2020 8:41 AM UTC
Question

Option value selected=selected in a form

Hello everyone,

 

I have a form with a Country select field. The first option is at follows:

<option value="">Select...</option>

 

What I need in reality is:

<option selected="selected" value="">Select...</option>

 

I've clicked on the Default checkbox within the Editor, without success.

 

I think this can be done via some simple JS script, but is there a way to avoid that and do it from the Editor?

 

Thanks,

Yavor

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

SanfordWhiteman
User Group Leader
User Group Leader
Dec 3, 2020 8:59 AM UTC

I can tell you how to do it, but first I need to question the UX.

 

A selected empty value will not make any changes on the Marketo server (it will not empty the field). So it's no different from having the field be optional. Why would you want to have a meaningless entry be the default selection?

Translate
Level 2
Dec 3, 2020 9:10 AM UTC

Hi Sanford,

 

thanks for the reply.

 

I know this is now the best thing to do from UX perspective. It looks like we have a script that will work only if we have selected="selected" on the Select option.

 

 

Translate
SanfordWhiteman
User Group Leader
User Group Leader
Dec 3, 2020 7:55 PM UTC

Very strange... I worry at what other assumptions that script makes. Most 3rd-party attribution libraries (if that's what this is) don't work correctly with Marketo forms, because they aren't built to understand the Marketo forms events.

 

Anyway:

MktoForms2.whenReady(function(mktoForm){ let formEl = mktoForm.getFormElem()[0], countryPlaceholderOption = formEl.querySelector("select[name='Country'] option[value='']"); countryPlaceholderOption.selected = true; countryPlaceholderOption.setAttribute("selected","selected"); });

 

Translate