Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Consulta De Paso De Variable Select Multiple

Estas en el tema de Consulta De Paso De Variable Select Multiple en el foro de Frameworks JS en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 07/11/2006, 09:53
 
Fecha de Ingreso: noviembre-2006
Mensajes: 9
Antigüedad: 17 años, 5 meses
Puntos: 0
Pregunta Consulta De Paso De Variable Select Multiple

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 ;)
  #2 (permalink)  
Antiguo 08/11/2006, 06:17
 
Fecha de Ingreso: noviembre-2006
Mensajes: 9
Antigüedad: 17 años, 5 meses
Puntos: 0
La respuesta esta marcada en rojo... jejeje me resulto :P...

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

function nuevoAjax()
{
/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
lo que se puede copiar tal como esta aqui */
var xmlhttp=false;
try
{
// Creacion del objeto AJAX para navegadores no IE
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
// Creacion del objet AJAX para IE
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E) { xmlhttp=false; }
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); }

return xmlhttp;
}
//var aux=0;
function cargaContenido(selectACargar,cargar)
{
// 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

// Extraigo el valor del combo que se ha cambiado
var valor=document.getElementById("select_"+selectAnte rior).options[document.getElementById("select_"+selectAnterior). selectedIndex].value;
var elemento;

if(selectACargar==2 && aux!=4){
//alert("valor"+ valor);
var aux=4;
var cargar = valor;
}


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="+selectAC argar+"&select1="+cargar, true);
ajax.onreadystatechange=function()
{
if (ajax.readyState==1)
{
// Mientras carga elimino la opcion "Elige" y pongo una que dice "Cargando"
elemento=document.getElementById("select_"+selectA Cargar);
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).inn erHTML=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>
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:35.