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
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?
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.
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");
});