-1
<select id="bethorse">
  <option value="horse1">White</option>
  <option value="horse2">Blue</option>
  <option value="horse3">Green</option>
  <option value="horse4">Brown</option>
</select>

S searched but the answers were for the selected text and I used this code bethorse= document.getElementById('bethorse').value;. It gives me number of the position the test. For example value 3 for horse4 just like in array.

Reporter
  • 3,776
  • 5
  • 31
  • 46
Shiva Khattri
  • 13
  • 1
  • 7

2 Answers2

0
var e = document.getElementById("bethorse");
var option = e.options[e.selectedIndex].value;

The variable option will hold the value of selected option.

deceze
  • 491,798
  • 79
  • 706
  • 853
Adrian
  • 7,768
  • 2
  • 23
  • 39
0

Your code is working in this example:

<select id="bethorse">
      <option value="horse1">White</option>
      <option value="horse2">Blue</option>
      <option value="horse3">Green</option>
      <option value="horse4">Brown</option>
    </select>

<button onclick="javascript:alert(document.getElementById('bethorse').value);">
    test
</button>
deceze
  • 491,798
  • 79
  • 706
  • 853
Stefan Koenen
  • 2,238
  • 2
  • 19
  • 32