Does the JavaScript onclick event not work on <select>

后端 未结 4 1876
青春惊慌失措
青春惊慌失措 2020-12-20 06:11

For some reason the code below it is not working correctly. Unless I\'m being quite stupid with my JavaScript I can\'t see what\'s going wrong besides the onclick events not

4条回答
  •  太阳男子
    2020-12-20 06:46

    DEMO

    var dropdown = document.getElementById('drop_down');
    
    dropdown.onchange = function() {
      var selected = dropdown.options[dropdown.selectedIndex].value;
    
      switch(selected) {
        case 'other':
          document.getElementById('other').value = "";
          document.getElementById('other').style.display = 'block'; 
          document.getElementById('otherBR').style.display = 'block';
          break;
        default:
          document.getElementById('other').style.display = 'none'; 
          document.getElementById('otherBR').style.display = 'none';
          break;
      }
    }
    

提交回复
热议问题