Advertisement
EvaldoMaciel

Select Index Insert HTML Text

Oct 29th, 2018
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.11 KB | None | 0 0
  1. <label for='check_motoristaSobrio'>Motorista Sóbrio</label>
  2. <select class='form-control ativ1 ativ7 ativ4 ativ6' id="check_motoristaSobrio" name="check_motoristaSobrio">
  3.     <option value="0">Selecione uma opção</option>
  4.     <option value="Sim">Sim</option>
  5.     <option value="Não">Não</option>
  6. </select>
  7. <div id="motoristaSobrioJustificativa"></div>
  8.  
  9.  
  10. <script type="text/javascript">
  11.     var selectElem = document.getElementById('check_motoristaSobrio')
  12.     var pElem = document.getElementById('motoristaSobrioJustificativa')
  13.    
  14.     // When a new <option> is selected
  15.     selectElem.addEventListener('change', function() {
  16.         var index = selectElem.selectedIndex;
  17.         // Add that data to the <p>
  18.         //  pElem.innerHTML = 'selectedIndex: ' + index;
  19.        
  20.         if (index == 1)
  21.         pElem.innerHTML = "<!-- Não tomou uma cachacinha hoje, então ta tudo certo -->";
  22.        
  23.         else if(index == 2)
  24.         pElem.innerHTML = "<textarea name=\"check_justMotSobrio\" class=\"form-control\" rows=\"4\" placeholder=\"Justificativa\nPor qual motivo esses ser humano esta chapado?\"></textarea>";
  25.        
  26.         else pElem.innerHTML = "<!-- Nada -->";
  27.     })
  28. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement