Ver Mensaje Individual
  #3 (permalink)  
Antiguo 22/01/2007, 13:36
Avatar de andresq
andresq
 
Fecha de Ingreso: enero-2007
Ubicación: Chiapas, México
Mensajes: 161
Antigüedad: 17 años, 3 meses
Puntos: 1
Re: Ejecutar funcion automaticamente

Cita:
Iniciado por carlosmbrizuela Ver Mensaje
La funcion cargocontenido() es una funcion js? que es ese 2 que le estas pasando?



Una de las maneras tb es usando Ajax.
la funcion cargacontenido si es JS y el 2 es un identificador ya que dentro de esa funcion tengo un switch, de todos modos aki te dejo la funcion:

Código PHP:
function cargaContenido(opc)
{
    switch(
opc)
    { 
        case 
1:
                            
ajax=nuevoAjax();

            
document.getElementById('proyecto').value;
            
document.getElementById('nomb').value;
                        
                
ajax.onreadystatechange alertContents;
                
ajax.open('POST'"Guardar_Proyecto.php"true);
                
ajax.setRequestHeader('Content-Type''application/x-www-form-urlencoded;');
                
ajax.send("proyecto="+a+"&nomb="+b);
                
Des_bloquear();
            
        break;
        case 
2:
            
//     I N I C I O
            
var valor=document.getElementById("capitulo").options[document.getElementById("capitulo").selectedIndex].value;
            
            if(
valor==0)
            {
                
// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
                
combo=document.getElementById('partida');
                
combo.length=0;
                var 
nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0nuevaOpcion.innerHTML="Seleccionar";
                
combo.appendChild(nuevaOpcion);    combo.disabled=true;
            }
            else
            {
                
ajax=nuevoAjax();
                
ajax.open("GET""Partidas.php?capitulo="+valortrue);
                
ajax.onreadystatechange=function() 
            { 
                if (
ajax.readyState==1)
                {
                    
// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
                    
combo=document.getElementById("partida");
                    
combo.length=0;
                    var 
nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0nuevaOpcion.innerHTML="Cargando...";
                    
combo.appendChild(nuevaOpcion); combo.disabled=true;    
                }
                if (
ajax.readyState==4)
                { 
                    
document.getElementById("fila_2").innerHTML=ajax.responseText;
                } 
            }
            
ajax.send(null);
        }
        break;
        
        case 
3:
        
            
indice2 document.getElementById('partida').selectedIndex;
            
indice3 document.getElementById('medida').selectedIndex;

            
            
document.getElementById('partida')[indice2].text;
            
document.getElementById('nombre').value;
            
document.getElementById('cantidad').value;
            
document.getElementById('medida')[indice3].text;
            
document.getElementById('precio').value;
            
document.getElementById('proyecto').value;
            
document.getElementById('justi').value;            
            
document.getElementById('total').value;                        
        
            if( 
== "Seleccionar")
                
window.alert("Seleccionar partida");
            else if( 
== "" )
                
window.alert"Introduzca el nombre del insumo" );
            else if( 
== "" )
                
window.alert"Introduzca la cantidad de insumo" );
            else if( 
== "Seleccionar" )
                
window.alert"Seleccione el tipo de medida del insumo" );
            else if( 
== "" )
                
window.alert"Introduzca el precio del insumo" );
            else
            {            
                
ajax.onreadystatechange alertContents;
                
ajax.open('POST','Guardar_Insumo.php'true);
                
ajax.setRequestHeader('Content-Type''application/x-www-form-urlencoded;');
                
ajax.send("proyecto="+g+"&capitulo="+a+"&partida="+b+"&nombre="+c+"&cantidad="+d+"&medida="+e+"&precio="+f+"&justi="+h+"&total="+i);
                
Limpiar();
            }

        break;
        
        case 
4:
        
                
ajax=nuevoAjax();
                var 
valor=document.getElementById("partida").options[document.getElementById("partida").selectedIndex].value;
                
ajax.open("GET""Desc_partida.php?partida="+valortrue);
                
ajax.onreadystatechange=function() 
                {     
                    if (
ajax.readyState==4)
                    { 
                        if( 
ajax.status == 200 )
                        {
                            
target "fila_3";
                            
document.getElementById(target).innerHTML ajax.responseText;
                            
document.getElementById("descri").dinnerHTML ajax.responseText;
                        }
                    } 
                }
                
ajax.send(null);
        break;
    }