O
O
olya_0972018-03-13 20:06:05
JavaScript
olya_097, 2018-03-13 20:06:05

Explain selectedOption please?

<select>
  <option value="Rock">Рок</option>
  <option value="Blues" selected>Блюз</option>
</select>

<script>
  var select = document.body.children[0];

  var selectedOption = select.options[select.selectedIndex]; //
  alert( selectedOption.value  + " - " + selectedOption.text );

</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Zhivagin, 2018-03-13
@Krasnodar_etc

select.options --- All possible options in array
select.selectedIndex --- index of selected option
selectedOption = array_options[ selected_index];
selectedOptions === {
value: 'option value',
text: 'option text',
...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question