Ver Mensaje Individual
  #14 (permalink)  
Antiguo 19/11/2009, 11:46
Avatar de uselox
uselox
 
Fecha de Ingreso: agosto-2008
Ubicación: Lima, Perú
Mensajes: 168
Antigüedad: 15 años, 8 meses
Puntos: 12
Respuesta: Textbox actaualizable con Combobox en PHP

Creo que te estas confundiendo revisa el manual de jquery.
debes de hacerlo de la siquiente manera.

quita del <body> onload="cargarClientes();"

cambia esto:
Cita:
Iniciado por basko3k Ver Mensaje
$(document).ready(function (){
$('#nombre').change(function (){
$.post('getClientes.php', {
// pasando parametros post
id_cliente: $(this).val()
}, function (response){
//prefiero hacer esto que poner el tipo en el 4 parametro de $.post
response = $.evalJSON(response);
$('#domicilio').val(response.domicilio);
$('#numero').val(response.numero);
$('#telefono').val(response.telefono);
})
});
});
por esto:

Código PHP:
var cargarClientes = function (obj){
    
obj.onchange = function (){
        var 
ajax nuevoAjax();
        
ajax.open('POST''getClientes.php'true);
        
ajax.onreadystatechange = function() {
            if (
ajax.readyState == 4) {
                
// verificar que esta respondiendo
                
alert(ajax.responseText);
                
response = eval(ajax.responseText);
                
document.getElementById('nombre').value response.nombre//igual a la columna en db
                
document.getElementById('Apellido').value response.Apellido//igual a la columna en db
                
document.getElementById('Direccion').value response.Direccion//igual a la columna en db
                
document.getElementById('Numero').value response.Numero//igual a la columna en db
                
document.getElementById('Depto').value response.Depto//igual a la columna en db
                
document.getElementById('Telefono').value response.Telefono//igual a la columna en db

             
}
        }
        
ajax.setRequestHeader("Content-Type""application/x-www-form-urlencoded");
        
ajax.send("id_cliente=" obj.value);
    }

y en getClientes.php quita todo el html.

asi te de deve de quedar

Código HTML:
<HTML>
<HEAD>
<STYLE>
.hideable { position: relative; visibility: visible; }
</STYLE>
<script>
function mostrar_ocultar(hide) {
	if (document.layers)
		document.contenido.visibility = hide ? 'show' : 'hide';
	else {
		var g = document.all ? document.all.contenido : document.getElementById('contenido');
		g.style.visibility = hide ? 'visible' : 'hidden';
	}
}
function nuevoAjax() {
	var xmlhttp=false;
	var ids = ["Msxml2.XMLHTTP.7.0","Msxml2.XMLHTTP.6.0","Msxml2. XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP. 3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

var cargarClientes = function (obj){
	obj.onchange = function (){
		var ajax = nuevoAjax();
		ajax.open('POST', 'getClientes.php', true);
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				// verificar que esta respondiendo
				alert(ajax.responseText);
				response = eval(ajax.responseText);
				document.getElementById('nombre').value = response.nombre; //igual a la columna en db
				document.getElementById('Apellido').value = response.Apellido; //igual a la columna en db
				document.getElementById('Direccion').value = response.Direccion; //igual a la columna en db
				document.getElementById('Numero').value = response.Numero; //igual a la columna en db
				document.getElementById('Depto').value = response.Depto; //igual a la columna en db
				document.getElementById('Telefono').value = response.Telefono; //igual a la columna en db

		 	}
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("id_cliente=" + obj.value);
	}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</HEAD>
<BODY>
<TABLE border=0 cellspacing=1 cellpadding=1>
<TR>
<TD height="134" VALIGN="top">
<FORM NAME="form0">
<font color="red" size="4">Delivery
<INPUT TYPE="checkbox" NAME="Accion" ONCLICK="mostrar_ocultar(this.checked);">
</FORM>
</TD>
<TD>
<SPAN ID="contenido" CLASS="hideable">
<FORM NAME="form1" method=POST action=traerDatos.php>
<p>
<?php
$result = mysql_db_query($dbname, "SELECT * FROM clientes", $dbcon);
echo "Seleccione cliente <SELECT size=0 cols=24 NAME=id_cliente onChange=\"cargarClientes(this);\">";
echo "<OPTION value='0'>Elija Cliente</option>";
while($row = mysql_fetch_array($result)){
	$id_cliente=$row["id_cliente"];
	$domicilio=$row["domicilio"];
	$nombre=$row["nombre"];
	$apellido=$row["apellido"];
	$nro=$row["numero"];
	$depto=$row["depto"];
	$telefono=$row["telefono"];
	echo"<OPTION value=$row[0]>$row[1] $row[2]</OPTION>";
	echo"</select>";
}
?>
		Nombre:
		<div id="nombre">$nombre</div>
		Apellido:
		<div id="Apellido"></div>
		Direccion:
		<div id="Direccion" value=$direccion></div>
		Numero:
		<div id="Numero"></div>
		Depto:
		<div id="Depto"></div>
		Telefono:
		<div id="Telefono"></div>
    	 </FORM>
  		</SPAN>
	  </TD>
     </TR>
   </TABLE>
 </BODY>
</HTML> 
getClientes.php
Código PHP:
<?php
include ("peligro.php");
include (
"conexion.php");
// aqui hacemos la coneccion mysq, etc
$rs mysql_db_query($dbname"SELECT * FROM clientes WHERE id_cliente=" $_POST['id_cliente'])or die(mysql_error());
$row mysql_fetch_assoc($rs);
echo 
json_encode($row);
?>

Última edición por uselox; 19/11/2009 a las 11:55