1

Quick question, I recently looked up how to retrieve the selected value of a drop down list, I found an answer but it uses syntax I am not familiar with, I was hoping someone could enlighten me as to how this works.

The solution offered was something like this:

var description = document.querySelector(".add__description");
description.options[description.selectedIndex].value

Why does the above work, but the following code:

description.options.selectedIndex.value

Does not?

Thanks in advance.

mattavero
  • 212
  • 1
  • 11
  • Because you want `description.value` description.selectedIndex is a variable and cannot be used in dot notation. Same as doing `description.options[3].value` to get the 4th option (arrays and array-like constructs are zero based in JS) You cannot do options.3.value either – mplungjan Sep 17 '19 at 16:50

0 Answers0