I
I
Ihor2020-12-13 20:58:05
JavaScript
Ihor, 2020-12-13 20:58:05

How to know what is selected in "select" JS?

Hello,
My django generates the following code:

<select name="docorderproduct_set-0-pack" id="id_docorderproduct_set-0-pack">
  <option value="" selected>---------</option>
  <option value="1">Мигдаль 1 кг </option>
</select>

And my JS code always returns None!
pack = document.getElementById("id_docorderproduct_set-0-pack").selectedOptions[0].value

And it doesn't matter which item I select in the dropdown list :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Melnikov, 2020-12-13
@Mi11er

Where is the script loaded? In HEAD or At the end of body ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question