Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/08/2016, 17:24
alvaro_trewhela
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Campo select con opción a escribir

Ve como andas con esto:

Código HTML:
Ver original
  1.     <head>
  2.         <script type="text/javascript">
  3.         function add(){
  4.         var text = document.getElementById("text");
  5.         var sel = document.getElementById("sel");
  6.        
  7.         var opt = document.createElement("option");
  8.        
  9.         opt.appendChild(document.createTextNode(text.value));
  10.         opt.setAttribute("value", text.value);
  11.        
  12.         sel.appendChild(opt);
  13.         }
  14.        
  15.         function see(){
  16.         alert(document.getElementById("sel").value);
  17.         }
  18.         </script>
  19.     </head>
  20.     <body>
  21.         <select id="sel">
  22.             <option value="uno">uno</option>
  23.             <option value="dos">dos</option>
  24.             <option value="tres">tres</option>
  25.         </select> Valor seleccionado: <input type="button" onclick="see();" value="Ver" /><br/>
  26.         Agregar opción: <input type="text" id="text"><input type="button" onclick="add();" value="Agregar" /><br/>
  27.     </body>
  28. </html>