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

Problema Php y lista desplegable

Estas en el tema de Problema Php y lista desplegable en el foro de Frameworks JS en Foros del Web. Tengo el siguiente codigo en el cual me muestra todo correcto excepto cuando se selecciona una opcion la cual no hay nada que mostrar muestra ...
  #1 (permalink)  
Antiguo 09/07/2008, 23:26
Avatar de Highlander  
Fecha de Ingreso: junio-2006
Ubicación: Concepción, Chile
Mensajes: 475
Antigüedad: 17 años, 10 meses
Puntos: 4
Problema Php y lista desplegable

Tengo el siguiente codigo en el cual me muestra todo correcto excepto cuando se selecciona una opcion la cual no hay nada que mostrar muestra un valor incorrecto, imagino que sera algun error de novato, ojala alguien sepa ya que lo habia preguntando antes en otro lado.

archivo combo.php

Código:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "xhtml1-transitional.dtd">
<html>
<head>
<title>Sentido Web - Combo AJAX</title>
<script type="text/javascript">
// <![CDATA[
function ajaxobj() {
	try {
		_ajaxobj = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			_ajaxobj = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			_ajaxobj = false;
		}
	}
   
	if (!_ajaxobj && typeof XMLHttpRequest!='undefined') {
		_ajaxobj = new XMLHttpRequest();
	}
	
	return _ajaxobj;
}

function carga(val) {
	var ajax = ajaxobj();
	ajax.open("POST", "ajax.php", true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			var datos = (ajax.responseXML).firstChild;
			var obj = document.getElementById("combo2");
			for (var i=0; i<obj.options.length; i++) {
        obj.removeChild(obj.firstChild);
      }
      for (var i=0; i<datos.childNodes.length; i++) {
        var elem = datos.childNodes[i].firstChild.data;
        obj.options[i] = new Option(elem);
      }
		}
	}
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send("&val="+val);
}

// ]] >
</script>
</head>
<body >
<p>

		<?php 
				   include("conexion.php");
				   $link=conectar();
			   	   $consulta = "SELECT * FROM ciudad ORDER BY NOM_CIUDAD"; 
			       $resultado = mysql_query($consulta,$link);
				   
		?>
            <select name="id_ciudad"  id="id_ciudad" onchange="carga(this.value)"> 
              <option value="" selected="selected">Seleccionar</option>
              <?php
					while($datos = mysql_fetch_array($resultado)){
					?>
              <option value="<?php echo $datos["ID_CIUDAD"] ?>"><?php echo $datos["NOM_CIUDAD"] ?></option>
              <?php
					}
					mysql_close($link);
			 		?>
            </select>


<select id="combo2">
  <option value="">Vacio</option>
</select>
</p>
</body>
</html>
Archivo ajax.php
Código:
<?php

	$val = $_POST["val"];
    $id_esta = array();
	$nom_esta = array();
	
	include("conexion.php");
	$link=conectar();
	$consulta = "SELECT * FROM establecimiento WHERE id_ciudad = '$val' ORDER BY id_esta"; 
	$resultado = mysql_query($consulta,$link);
	$j=0;
	while($datos = mysql_fetch_array($resultado)){
	$id_esta[]=$datos["ID_ESTA"];
	$nom_esta[]=$datos["NOM_ESTA"];
	$j++;
	} 
	mysql_close($link);
	
	$xml .= '<datos>';
    for ($i=0; $i<=$j; $i++){
    $xml .= '<valor>'.$nom_esta[$i].'</valor>'; 
	}
	$xml .= '</datos>';
	header('Content-type: text/xml');
	echo $xml;	
	 
	 
	/* $xml .= '<datos>';
  for ($i=1; $i<=5; $i++) {
    $xml .= '<valor>'.$val.'</valor>'; 
	}
	$xml .= '</datos>';
	header('Content-type: text/xml');
	echo $xml;	 */
?>
  #2 (permalink)  
Antiguo 09/07/2008, 23:30
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Problema Php y lista desplegable

Tema trasladado a AJAX.
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 22:38.