Ver Mensaje Individual
  #8 (permalink)  
Antiguo 31/03/2008, 15:04
joseverdugo
 
Fecha de Ingreso: febrero-2008
Mensajes: 8
Antigüedad: 16 años, 2 meses
Puntos: 0
Re: Refrescar lista desplegable de pagina padre desde pagina hija en ie6

mas....


index.php
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
<script language="JavaScript" src="recarga_combo.js" type="text/javascript"></script>


<script language="JavaScript" type="text/javascript">
function valida_form(f)
{    
    
    f.submit();

}
</script>

</head>

<?php 
require("afp.class.php");
require(
"db.class.php");

$afp = new afp();

?>
<body>     
    
<p><strong>Agregar</strong></p>
<form id="form1" name="form1" method="get" action="">

  <table  width="940" border="0" class="borde_linea">
  <tr>
  <th colspan="6" align="left"> <strong>Datos Personales</strong> </th>
  </tr>
    <tr>
      <td width="75" >Rut</td>
      <?php 
      
if(isset($_GET["opcion"]) && $_GET["opcion"] == "editar"){
          echo 
"<td width=\"198\"><input type=\"hidden\" name=\"rut\" id=\"rut\"  value=\"\"/></td>";
      }else{
          echo 
"<td width=\"198\"><input type=\"text\" name=\"rut\" id=\"rut\"  tabindex=\"2\" value=\"\"/>";
          
          echo 
"</td>";

      }
      
?>
      
      <td width="100"></td>
      <td></td>
      <td width="110">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Nombre</td>
      <td><label>
        <input type="text" name="nombre" id="nombre" tabindex="3" value="" />
     
        </label></td>
      <td>Apellido P.</td>
      <td><label>
        <input type="text" name="apellidop" id="apellidop" tabindex="4" value="" />
      
      </label></td>
      <td>Apellido M.</td>
      <td><label>
        <input type="text" name="apellidom" id="apellidom" tabindex="5" value="" />
       
      </label></td>
    </tr>
    <tr>
      <td>AFP<a href="javascript:void(null)" onclick="window.open('../web/afp.php','','width=450,height=400,resizable=yes,scrollbars=yes');return false;">[+]</a></td>
      <td><label>
        <select name="codafp" id="codafp" tabindex="15" onKeypress=buscar_op(this) onblur=borrar_buffer() onclick=borrar_buffer()>
          <?php 
          $afp
->lista_select();
          
?>
        </select>
       
      </label>
           </td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
<input type="hidden" name="opcion" id="opcion" value="save" />
   <input type="hidden" name="est" id="est" value="" />
<input type="button" name="button" value="Guardar" onclick="valida_form(this.form)" tabindex="20" />
   
   
</form>


</body>
</html>
recarga_combo.php
Código PHP:
<?php
require("afp.class.php");
require(
"db.class.php");


$combo=$_GET["select"];
$index=$_GET["tab"];

//combo id afp
if($combo == "codafp")
{    
    echo 
"<select name=\"".$combo."\" id=\"".$combo."\" tabindex=\"".$index."\" onKeypress=buscar_op(this) onblur=borrar_buffer() onclick=borrar_buffer()>";
    
$obj = new afp();
    
$obj->lista_select();
    echo   
"</select>";    
}

?>
recarga_combo.js
Código PHP:
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)
        {
            if (!
xmlhttp && typeof XMLHttpRequest!='undefined'xmlhttp=new XMLHttpRequest();
        }
    }
    return 
xmlhttp;
}



function 
cargaContenido(idSelectDestino)
{

    
    var 
selectDestino=document.getElementById(idSelectDestino);


    
// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
    
var ajax=nuevoAjax();
    
//dado que IE6 guarda en la cache la respuesta, se genera una direccion siempre distinta gracias a aleatorio()
    
ajax.open("GET""recarga_combo.php?select="+idSelectDestino+"&tab="+selectDestino.tabIndex+"&aleat="+Aleatorio(), true);

    
ajax.onreadystatechange=function()
    {
        
        if (
ajax.readyState==4)
        {
            
selectDestino.parentNode.innerHTML=ajax.responseText;
        }
    }
    
ajax.send(null);

}



function 
Aleatorio(){
    
aleat Math.random() * 5000;
    
aleat Math.round(aleat);
    return 
aleat;

script_postgres.sql
Código PHP:
CREATE TABLE afp
(
  
"codAfp" serial,
  
nombre character varying NOT NULL,
  
porcentaje numeric,
  
CONSTRAINT afp_pkey PRIMARY KEY ("codAfp"),
  
CONSTRAINT afp_nombre_key UNIQUE (nombre)
) ;

CREATE OR REPLACE VIEW vista_afp AS 
 
SELECT afp."codAfp" AS "Cod AFP"afp.nombre AS "AFP"afp.porcentaje AS "Porcentaje"
   
FROM afp
  ORDER BY afp
.nombre;



CREATE OR REPLACE FUNCTION insertafp(nom character varyingporc numericcod integer)
  
RETURNS character varying AS
$BODY$
declare

idafp integer;

Begin

    BEGIN

    update afp set nombre
=nomporcentaje=porc where "codAfp"=cod;

    if 
not found then

        select into idafp nextval
('"afp_codAfp_seq"');

        
insert into afp (nombre,porcentaje,"codAfp")
        
values (nom,porc,idafp);

        RETURN 
idafp;
    else

        RETURN 
cod;

    
end if;

    
EXCEPTION 
        WHEN unique_violation THEN
        
RETURN '-1';
        
when foreign_key_violation then
        
RETURN '-2';
        
    
END;

End
$BODY
$
  
LANGUAGE 'plpgsql' VOLATILE