Skip to main content
WolfShade
Legend
March 1, 2016
Answered

SELECT (multiple) options ignoring selected attribute

  • March 1, 2016
  • 2 replies
  • 10080 views

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 has been closed for replies.
Correct answer haxtbh

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?

2 replies

Inspiring
March 2, 2016

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?

WolfShade
WolfShadeAuthor
Legend
March 2, 2016

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,

^_^

Inspiring
March 2, 2016

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?

Carl Von Stetten
Legend
March 1, 2016

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.

WolfShade
WolfShadeAuthor
Legend
March 2, 2016

Hi, Carl,

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

V/r,

^_^