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

Esta si es la ultima y si no sale matate hahaha..

Código HTML:
<HTML>
<HEAD>
<STYLE type="text/css">
.hideable { position: relative; visibility: visible; }
</STYLE>
<script type="text/javascript">
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){
	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').innerHTML = response.nombre;
			document.getElementById('Apellido').innerHTML = response.apellido;
			document.getElementById('Direccion').innerHTML = response.direccion; 
			document.getElementById('Numero').innerHTML = response.numero; 
			document.getElementById('Depto').innerHTML = response.depto; 
			document.getElementById('Telefono').innerHTML = response.telefono; 
		 	}
	}
	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 NAME="Accion" TYPE="checkbox" ONCLICK="mostrar_ocultar(this.checked);" value="" checked>
</FORM>
</TD>
<TD>
<SPAN ID="contenido" CLASS="hideable">
<FORM NAME="form1" method=POST action=traerDatos.php>
<p>
<?php
# coneccion a la db
require_once('conexion.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>";
?>
<div class="box-costumer">
		Nombre: <label id="nombre"></label><br />
		Apellido: <label id="Apellido"></label><br />
        Direccion: <label id="Direccion"></label><br />
        Numero: <label id="Numero"></label><br />
		Depto: <label id="Depto"></label><br />
		Telefono: <label id="Telefono"></label>
</div>
    	 </FORM>
  		</SPAN>
	  </TD>
     </TR>
   </TABLE>
 </BODY>
</HTML> 

getClientes.php
Código PHP:
<?php 
include ("peligro.php"); 
include (
"conexion.php"); 
$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; 20/11/2009 a las 10:16