0

I Want to set the selected value of a html select with the help of javascript. This is my current js code:

var g = document.getElementById('g');
g.value = '1';

While this is my select:

   <select id="g">
    <option value="" disabled selected>  Geschlecht...</option>
    <option value="1" id="M">Männlich</option>
    <option value="2" id="F">Weiblich</option>
  </select>

However this doesn't seem to work as i get the following error:

Uncaught TypeError: Cannot set properties of null (setting 'value')

Holunk
  • 23
  • 4

0 Answers0