Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/01/2011, 12:58
Avatar de RenacidoJH2
RenacidoJH2
 
Fecha de Ingreso: enero-2011
Mensajes: 12
Antigüedad: 13 años, 3 meses
Puntos: 2
Pregunta Ayuda con Codigo

Cordial Saludo...

Lo que trato de hacer en el siguiente codigo, es que al seleccionar una opcion en el primer select, se carguen las "subopciones" correspondientes en el segundo select. pero no logro que me funcione. aqui les dejo el codigo para ver si alguien me ayuda con mi problema:

Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Prueba</title>
<script language="javascript">
function opciones(idopc) {
	select2 = document.forms['form1'].elements['select2'];
	if (idopc == "opc1") {
		select2.options[1] = new Option("Opcion 1A","1A");
		select2.options[2] = new Option("Opcion 1B","1B");
		select2.options[3] = new Option("Opcion 1C","1C");
	} else if (idopc == "opc2") {
		select2.options[1] = new Option("Opcion 2A","2A");
		select2.options[2] = new Option("Opcion 2B","2B");
		select2.options[3] = null;
	} else {
		for (int i = 1; i <= select.options.length; i++)
			select2.options[i] = null;
	}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <select name="select" id="select" onchange="opciones(this.value);">
      <option>Seleccione uno...</option>
      <option value="opc1">Opcion 1</option>
      <option value="opc2">Opcion 2</option>
    </select>
  </p>
  <p>
    <select name="select2" id="select2">
      <option>Seleccione uno...</option>
    </select>
  </p>
  <p>
    <input type="submit" name="button" id="button" value="Enviar" />
  </p>
</form>
</body>
</html>