Does the JavaScript onclick event not work on <select>

后端 未结 4 1875
青春惊慌失措
青春惊慌失措 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 07:00

    Add this function to your JS:

    function showHideOther(){
        if (document.getElementById('drop_down').value == 'other') {
             showOther();   
        } else {
             hideOther();   
        }
    }
    

    And change your select element like this:

    
    

    function showHideOther() {
      if (document.getElementById('drop_down').value == 'other') {
        showOther();
      } else {
        hideOther();
      }
    }
    
    function showOther() {
      document.getElementById('other').value = "";
      document.getElementById('other').style.display = 'block';
      document.getElementById('otherBR').style.display = 'block';
    }
    
    function hideOther() {
      document.getElementById('other').style.display = 'none';
      document.getElementById('otherBR').style.display = 'none';
    }
    #other {
      display: none;
    }
    #otherBr {
      display: none;
    }
    
    
    

提交回复
热议问题