Skip to main content
WolfShade
Legend
Mar 1, 2016 10:14 PM UTC
Answered

SELECT (multiple) options ignoring selected attribute

Hello, all,

I've got CF code that is being used with a SELECT tag (multiple attribute), and it seems as though the SELECT tag is ignoring the selected attribute for the child options.

For example, I have code that will generate the following HTML:

<select name="selectA" id="selectA" multiple>

    <option value="">ALL</option>

    <option value="Option 1" selected="selected">Option 1</option>

    <option value="Option 2">Option 2</option>

    <option value="Option 3" selected="selected">Option 3</option>

</select>

But when the page loads, none of the options are selected.  Any suggestions?  What am I missing, here?

V/r,

^_^

This topic is closed to new replies. Start a new post to keep the conversation going.
haxtbhCorrect answer
Inspiring
Mar 2, 2016 4:10 PM UTC

Yeah, that's what is so frustrating about this.

I've done a lot of looking around and such; HTML validator isn't throwing any errors; I understand that 'selected' and 'multiple' are booleans and don't take values (or, rather, anything between  =" and " is ignored); the View Source code is showing that the selected attribute IS being applied to certain options; a jsfiddle does as expected/desired.

I cannot understand what is preventing this from working on my project.  IE, FF, and Chrome all do the same, so I don't think it's browser related.

V/r,

^_^


There is no javascript / jquery anywhere that interacts with this dropdown?

17 replies

Inspiring
Mar 2, 2016 3:37 PM UTC

Is this code what you are expecting it todo or what is actually output once its done. I.e. is this what shows when you inspect element on the page?

Translate
WolfShade
WolfShadeAuthor
Legend
Mar 2, 2016 3:44 PM UTC

Hi, haxtbh,

Yes, if you "View Source" and look at the OPTION tags of the SELECT, there are some that have the 'selected' attribute and some that don't, based upon data from the database.

I've tried <select multiple> and <select multiple="multiple">, I've tried <option selected> and <option selected="selected">, no change.

V/r,

^_^

Translate
Inspiring
Mar 2, 2016 3:49 PM UTC

Technically there is nothing wrong with what you have posted so without some more code or a repro case then its hard to know what is causing it.

Which browsers are you using?

Translate
Carl Von Stetten
Legend
Mar 1, 2016 10:45 PM UTC

Try changing the select tag to multiple="multiple". If that doesn't work, switch it back and change the options with selected="selected" to just selected.

Translate
WolfShade
WolfShadeAuthor
Legend
Mar 2, 2016 2:40 PM UTC

Hi, Carl,

I've tried both in each combination, no changes.

V/r,

^_^

Translate