1

I have a select element and no matter what I try, the option values are blank. The number of options in the drop down is correct, but they are blank. Here is the html:

          <label for="accountBrokerageName">Brokerage:</label>
          <select id="accountBrokerageName">
             <option value="Interactive Brokers, LLC"></option>
             <option value="Vanguard"></option>
          </select>

I'm assuming some css from another library is overriding the standard select>option css. I've tried commenting out each linked library one at a time but no joy. I've tried adding a .clear-css class to the option like this:

.clear-css {
  all:unset;
}

and append it to all options using jquery just before it is used, like this:

$('option').addClass('clear-css');

Still blank.

I've also tried

.clear-css {
  all:initial;
}

Still blank.

I also tried adding the clear-css class to the select element, but that causes the whole select element to disappear.

Any suggestions?

1
  • 3
    You forgot to add the html content of options. Do <option value="Interactive Brokers, LLC">Interactive Brokers</option><option value="Vanguard">Vanguard</option>. It has nothing to do with css Commented May 3, 2021 at 22:47

2 Answers 2

1

You need to include the values for each option between the opening and closing <option> tags. The value doesn't need to match the text content. In fact, it's usually better to remove any special characters and even spaces when working with external APIs, like this:

// This JS is just for the sake of example, to log the new value with each change
const select = document.getElementById('accountBrokerageName');
select.addEventListener('change', () => console.log(select.value));
<label for="accountBrokerageName">Brokerage:</label>
<select id="accountBrokerageName">
 <option value="" disabled selected>Choose an option...</option>
 <option value="interactive-brokers-llc">Interactive Brokers, LLC</option>
 <option value="vanguard">Vanguard</option>
</select>

Sign up to request clarification or add additional context in comments.

2 Comments

Well that's got to be the blunder of blunders of all time. I tried everything but the obvious! Too long staring at the code I guess. But I learned something from you about the arrow function shortcut and the disabled selected technique. Thank you!
Glad I could help!
1

Select values must be within the actual <option> tags:

<label for="accountBrokerageName">Brokerage:</label>
<select id="accountBrokerageName">
 <option value="Interactive Brokers, LLC">Interactive Brokers, LLC</option>
 <option value="Vanguard">Vanguard</option>
</select>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.