Ver Mensaje Individual
  #6 (permalink)  
Antiguo 07/11/2006, 09:50
xandrex
 
Fecha de Ingreso: noviembre-2006
Mensajes: 9
Antigüedad: 17 años, 5 meses
Puntos: 0
Pregunta I Need Your Help

Hola, saludos amigos.. soy nuevo por aki y espero seguir un buen tiempo mas y blablabla jejeje...

tengo un dilemilla k no me resulta la solucion y necesito k me ayuden, me urge un poko...

Problem: Tengo tres Lista menus (<input select>) y sucede k necesito k al seleccionar el primer valor me despliegue el segundo de acuerdo al seleccionado anteriormente... y k al seleccionar el segundo valor del segundo select me despliegue el tercer select PERO dependiendo del select 1 y el select 2 seleccionado... osea k para el despliegue del tercer select necesito pasar los valores del uno y dos... pero no me resulta por k los valores se reemplazan... hay una forma de mantener el primer valor en una variable auxiliar y k cuandfo se reemplace no lo haga para el auxiliar...?????

--------------------------------------------------------------------------
--------------------------------------------------------------------------
Código:
MZ11.PHP

<?php
function generaSelect()
{
	$msconnect = mssql_connect("xxx", "xxx", "xxx") or die("No se pudo conectar con el servidor!!!");
	
	$sql5 = mssql_query("select codigo,descripcion from gen_tabcod where empresa='001' and tipo='con_ccosto'",$msconnect);

	// PRIMER SELECT
	echo "<select class='combo' id='select_1' name='select_1' onChange='cargaContenido(2,1)'>"; //PASO PRIMER VALOR
	echo "<option value='0'>Elige</option>";
	while($registro=mssql_fetch_row($sql5))
	{
		echo "<option value='".$registro[0]."'>".$registro[0]." - ".$registro[1]."</option>";
	}
	echo "</select>";
}
?>

<html>
<head>
<style type="text/css"> 
.punteado 
{ 
	border-style:dotted; 
	border-color:#000000; 
	background-color:#EAEAEA;
	font-family:Verdana; 
	font-size:10px; 
	text-align:center;
}

.combo
{
	font-family:Verdana; 
	font-size:10px; 
	border-color:#CCCCCC;
}
.style4 {border-style: dotted; border-color: #000000; background-color: #EAEAEA; font-family: Verdana; font-size: 10px; text-align: center; color: #000000; font-weight: bold; }
</style>

<script language="javascript" type="text/javascript">


function cargaContenido(selectACargar,cargar)
{ //RECIBO DOS VALORES PARA PODER MANTENER EL VALOR DEL PRIMER SELECT Y EL SGUNDO
	// Recibo el número correspondiente al combo que se debe llenar de datos
	var selectAnterior=selectACargar-1; // Obtengo el número del combo que activó el evento onChange
	var cargar=selectAnterior;
	// Extraigo el valor del combo que se ha cambiado
	var valor=document.getElementById("select_"+selectAnterior).options[document.getElementById("select_"+selectAnterior).selectedIndex].value;
	var elemento;
	
	if(valor!=0)
	{
		ajax=nuevoAjax();
		// Envio al servidor el valor seleccionado y el combo al cual se le deben poner los datos
		ajax.open("GET", "mz11.php?seleccionado="+valor+"&select="+selectACargar+"&select1="+cargar, true); //PASO VARIABLES POR URL
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Elige" y pongo una que dice "Cargando"
				elemento=document.getElementById("select_"+selectACargar);
				elemento.length=0;
				var opcionCargando=document.createElement("option"); opcionCargando.value=0; opcionCargando.innerHTML="Cargando...";
				elemento.appendChild(opcionCargando); elemento.disabled=true;	
			}
			if (ajax.readyState==4)
			{
				// Coloco en la fila contenedora los datos que recivo del servidor
				document.getElementById("fila_"+selectACargar).innerHTML=ajax.responseText;
			} 
		}
		ajax.send(null);
	}
	
	/* Colocamos mediante los whiles los selects en "Selecciona opción..." cuando el select anterior
	ha quedado en estado "Elige" */
	var x=1, y=null;
	while(x<=2)
	{
		valor=document.getElementById("select_"+x).options[document.getElementById("select_"+x).selectedIndex].value;
		if(valor==0)
		{
			while(x<=2) 
			{
				y=x+1;
				elemento=document.getElementById("select_"+y);
				elemento.length=0;
				var opcionSelecciona=document.createElement("option"); opcionSelecciona.value=0; opcionSelecciona.innerHTML="Selecciona opci&oacute;n...";
				elemento.appendChild(opcionSelecciona); elemento.disabled=true;
				x++;
			}
		}
		x++;
	}
	
}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ejemplo</title>
</head>

<body>
<center>
<table border="1" width="634" style="border-style:none;">
  <tr>
    <td class="style4">Centro de Costo</td>
    <td  class="punteado"><?php generaSelect(); ?></td>
    </tr>
  <tr>
    <td class="style4">Item</td>
    <td id="fila_2" class="punteado"><select class="combo" disabled="disabled" id="select_2" name="select_2">
      <option id="valor_defecto" value="0">Selecciona opci&oacute;n...</option>
    </select></td>
    </tr>
  <tr>
    <td width="167" class="style4">SubItem</td>
    <td id="fila_3" width="233" class="punteado"><select class="combo" disabled="disabled" id="select_3" name="select_3">
      <option id="valor_defecto" value="0">Selecciona opci&oacute;n...</option>
    </select></td>
	</tr>
</table>
</center>
</body>
</html>
--------------------------------------------------------------------------
--------------------------------------------------------------------------
Código:
MZ11.PHP

<?php

$valor=$_GET["seleccionado"]; $selectACargar=$_GET["select"];
$ccosto=$_GET["select1"];
//if(validaEntrada($valor, $selectACargar))
//{
//
	// Si el numero corresponde a un codigo de pais valido paso a procesar
$conexion = mssql_connect("Flex", "flexline", "flexline") or die("No se pudo conectar con el servidor!!!");
if($selectACargar==2){
	// Genero la consulta trayendo todos los estados que correspondan al codigo de pais elegido
$consulta = mssql_query("select distinct s.cod_item,u.descripcion from con_asociacc s, gen_tabcod u where s.cod_ccosto='$valor' and s.empresa='001'
and u.tipo='con_item' and s.empresa=u.empresa and u.codigo=cod_item order by descripcion",$conexion);

$aux=$ccosto;
}

if($selectACargar==3){
	// Genero la consulta trayendo todos los estados que correspondan al codigo de pais elegido
$consulta = mssql_query("SELECT distinct a.cod_subitem, b.descripcion
				FROM con_asociacc a join gen_tabcod b on b.codigo=a.cod_subitem
				WHERE a.empresa='001'
				and b.empresa='001'
				and b.tipo='GOL_SUBITEM' 
				order by b.descripcion",$conexion);}

	//mssql_close($conexion);and a.cod_item='$itemgasto'				and a.cod_ccosto='$valor'	
	///////////////////////////////////////
if($selectACargar==2)
		echo "<select class='combo' onChange='cargaContenido(3,$aux)' id='select_$selectACargar' name='select_$selectACargar'>"; //NEVIO EL VALOR DEL PRIMER SELECT Y EL "SUSPUESTO VALOR DEL SELECT DOS K NO ME FUNCIONA"
	else
		echo "<select class='combo' id='select_$selectACargar' name='select_$selectACargar'>";		
	
	echo "<option value='0'>Elige</option>";
	while($registro=mssql_fetch_row($consulta))
	{
		// Paso a HTML acentos y ñ para su correcta visualizacion
		$registro[1]=htmlentities($registro[1]);
		// Imprimo las opciones del select
		echo "<option value='$registro[0]'>$ccosto ($valor) $registro[0] - $registro[1]</option>";
	}			//$ccosto $valor 
	echo "</select>";
//}////////////////////////////////////////////////////////////


?>
EJEMPLO:

select 1: cod: 1230 - planeta tierra

select 2: cod: 1230 - cod2: 56 - Pais Chile

select 3: cod: 1230 - cod2: 56 - cod3: 06 Ciudad Santiago


como veran al pricipio paso una variable y despues dos para ejecutar el ultimo select.


GRACIAS DE ANTEMANO.... ESPERO K ME AYUDEN ;)