Ver Mensaje Individual
  #4 (permalink)  
Antiguo 12/07/2012, 22:43
racba
 
Fecha de Ingreso: diciembre-2004
Mensajes: 21
Antigüedad: 19 años, 5 meses
Puntos: 3
Respuesta: link dependiente de un select

Hola a todos:
Que les parece este codigo:
Código HTML:
Ver original
  1. <script type="text/javascript">
  2.  function cambiar_link(){
  3.       var _link = new Array('milink1', 'milink2', 'milink3');
  4.       alert('Este es el array con todos los links: '+_link);
  5.       _div = document.getElementById('id_div');
  6.       _select = document.getElementById('id_select')
  7.       _optioncant = _select.length;
  8.       alert ('Las cantidad de opciones son: '+_optioncant);
  9.       _option=_select.options[_select.selectedIndex].index;
  10.       alert('Esta es la opcion numero: '+_option+ '. Recordar que la primera opcion es 0');
  11.       for (i=1; i< _optioncant; i++){
  12.           if (i == _option){
  13.            _div.innerHTML = '<a href="http://www.'+_link[i-1]+'.com">Mi link '+i+'</a>';
  14.             break;
  15.           }
  16.        }
  17.     }
  18.    </script>
  19. </head>
  20.   <select id="id_select" onchange="cambiar_link()">
  21.    <option>OPCIONES</option>
  22.    <option>opcion 1</option>
  23.    <option>opcion 2</option>
  24.    <option>opcion 3</option>
  25.   </select>
  26.   </form>
  27.   <div id='id_div'></div>
  28.   </body>
  29.  </html>