Ver Mensaje Individual
  #3 (permalink)  
Antiguo 11/05/2007, 07:19
Avatar de ZiTAL
ZiTAL
 
Fecha de Ingreso: marzo-2004
Ubicación: Bermio (Bizkaia)
Mensajes: 1.545
Antigüedad: 20 años, 2 meses
Puntos: 62
Re: Llenar input de un formulario segun desplegable

te pongo un ejemplo "fresquisimo" ;)

index.php
Código HTML:
<html> 
<head> 
<script type="text/javascript"> 
function ajaxFunction()
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    return xmlHttp;
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      return xmlHttp;
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        return xmlHttp;
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
  }
function fajax()    
{
    var titulo,texto,ajax,resul;
    //
    titulo = document.getElementById('titulo');
    texto = document.getElementById('texto');
    //
    ajax=ajaxFunction();
    ajax.open("GET","ajax.php",true);
    //
    ajax.send(null);
    ajax.onreadystatechange=function()
     {
      if(ajax.readyState==3)
        {
			document.getElementById('capa').innerHTML="Cargando...";
        }          
      else if(ajax.readyState==4)
        {
         	document.getElementById('capa').innerHTML="";
         	//
        	resul=ajax.responseText.split('|');
        	titulo.value=resul[0];
        	texto.value=resul[1];
        }    
     }
} 
</script> 
</head> 
<body> 
<form> 
<input type="button" value="Cargar datos" onclick="fajax()" /> 
<input type="text" name="titulo" id="titulo" /> 
<input type="text" name="texto" id="texto" /> 
</form> 

<div id="capa">
</div>

</body> 
</html> 
ajax.php
Código PHP:
<?php
//Aqui recogemos datos de la BD bla bla bla
$id=20;
$nombre="Pelo Whisky";
echo 
$id."|".$nombre;
?>
se entiende la jugadita no? ;)
__________________
http://zital.no-ip.org
____________________

Euskerie ahuen eta bijotzan