0

I am trying to stop this drop down box from changing size whenever it has an option in it that is longer than the set 200px width of the dropdown box. The options are just being loaded by a json file - the issue can be seen below in images:

The list loads a selection of game names, when the list loads if there is an option that isn't longer than the dropdown menu it is fine and is the correct width as shown by the red line:

http://postimg.org/image/dxx0u0wup/

But as soon as it has an option in it that is longer than the dropdown it results in this : (The red line indicates the end of a window but it is currently transparent so the form you see is simply a div centred in a window)

http://postimg.org/image/kbtf1xs1d/full/

you can see the css I used, firstly I tried setting different widths but none of them changed anything then I thought it could be something to do with overflow but that didn't work either

HTML for the dropdown

    <label for="state">Games: </label>
    <select id="gamesSelect" name="gamesSelect">
    </select>

then the JS that fills it

function loadGames() {

              console.log("Getting games list");

              $.getJSON("games.json", function (games) {

                  console.log(games);

                  var gamesSelect = document.getElementById("gamesSelect");
                  for (var i = 0; i < games.array.length; i++) {
                      var opt = games.array[i];
                      var el = document.createElement("option");
                      el.textContent = opt;
                      el.value = opt;
                      el.width = "200";
                      gamesSelect.appendChild(el);
                  }


              });

        }

some people are saying its a duplicate, it is but only because the answers did not work for me - it is the same sort of issue but none were working so I made this

Rai Ammad Khan
  • 1,521
  • 2
  • 14
  • 26
user3195250
  • 127
  • 2
  • 13

1 Answers1

0

Change the code as follows:

#gameSelect
{
  width:200px;
  overflow:scroll;
}

#gameSelect option
{
  width:200px;
  overflow:scroll;
}
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Rai Ammad Khan
  • 1,521
  • 2
  • 14
  • 26