Ver Mensaje Individual
  #30 (permalink)  
Antiguo 07/01/2009, 13:56
Avatar de farra
farra
 
Fecha de Ingreso: marzo-2008
Ubicación: Aqui estoy
Mensajes: 574
Antigüedad: 16 años, 1 mes
Puntos: 20
De acuerdo Respuesta: Mi pagina aparece en blanco =(

no podes pasar parametros de una variable de java script a una de PHP, tenes que usar ajax y pasarlo por GET o POST.... NO HAY OTRA FORMA...!

tenes que crear 2 paginas, 1 con html y javascript y otra exclusiva de php..

aca te doy un ejemplo de usar ajax lo hise parecido a lo que vos necesitas despues lo adaptas nomas a tus necesidades:


Archivo: test.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=iso-8859-1" />
<
title>Documento sin t&iacute;tulo</title>
<
Script language="javascript" type="text/javascript">
// Inicio AJAX
function toggle(what) {
        var 
aobj document.getElementById(what);
        if( 
aobj.style.display == 'none' ) {
               
aobj.style.display '';
        } else {
               
aobj.style.display 'none';
        }
}
function 
CrearXMLHttp(){
    
XMLHTTP=false;
    if(
window.XMLHttpRequest){
        return new 
XMLHttpRequest();
    }else if(
window.ActiveXObject){
        return new 
ActiveXObject("Microsoft.XMLHTTP");
    }
}
// suponiendo que tu div se llama loading
function OpenPage(url,id){
//alert(url+' '+id);
    
req=CrearXMLHttp();
    if(
req){
        
req.onreadystatechange = function() { manejador(id); }; // aca cambie
        
req.open("POST",url,true);
        
req.send(null);
                
toggle('loading'); // ojo aqui
    
}
}
function 
manejador(id){
    if(
req.readyState == 4){
        if(
req.status == 200){
                        
toggle('loading'); // ojo aca
            
document.getElementById(id).innerHTML=req.responseText;
        }else{
            
alert("Error"+req.statusText)
        }
    }
}

// FIN AJAX


function guardar(){

    
// dando valor a las variables
var noCotizacion document.getElementById('noCotizacion').value;
var 
cantidad document.getElementById('cantidad').value;
var 
descripcion document.getElementById('descripcion').value
var 
tiempoEntrega document.getElementById('tiempoEntrega').value
var 
precioUnitario document.getElementById('precioUnitario').value
var 
costoTotal document.getElementById('costoTotal').value;

//enviando a php para guardar
var datos "guardar.php?noCotizacion="+noCotizacion+"&cantidad="+cantidad+"&descripcion="+descripcion+"&tiempoEntrega="+tiempoEntrega+"&precioUnitario="+precioUnitario+"&costoTotal="+costoTotal;



OpenPage(datos,'tdc');

        
    }
</script>
</head>

<body>
<table width="100%" border="1">
  <tr>
    <td id="tdc">
noCotizacion: <input name="noCotizacion" type="text" id="noCotizacion" /><br />
cantidad: <input name="cantidad" type="text" id="cantidad" /><br />
descripcion: <input name="descripcion" type="text" id="descripcion" /><br />
tiempoEntrega: <input name="tiempoEntrega" type="text" id="tiempoEntrega" /><br />
precioUnitario: <input name="precioUnitario" type="text" id="precioUnitario" /><br />
costoTotal: <input name="costoTotal" type="text" id="costoTotal" /><br />

    <div id="loading" style="display:none;" align="left">
          <table width="50" border="1" style="border-collapse:collapse;">
            <tr>
              <td bgcolor="#FF0000"><span style="color:#FFFFFF; font-weight:bold;">Cargando...</span></td>
            </tr>
          </table>
      </div></td>
      </tr>
</table><br /><a href="javascript:guardar();">Pasar datos a PHP</a>
</body>
</html> 

Archivo: guardar.php
Código PHP:

<?php 
/*

        mysql_connect("server", "name", "pass") or die ("Error en conexion");
        mysql_select_db("sci") or die ("BD erronea");
        
        $insertSQL = "INSERT INTO cotizacion (noCotizacion,compania,atiende,conCopia,fecha,subtotal,total) VALUES ('".$noCotizacion."','".$compania."','".$atiende."','".$conCopia."','".$fechaD."/".$fechaM."/".$fechaA."','".$subTotal."','".$total."');";
        
          $Result1 = mysql_query($insertSQL) or die("no se hace el insert 1");
        
        
        
        
            mysql_connect("server", "name", "pass") or die ("Error en conexion");
            mysql_select_db("sci") or die ("BD erronea");
*/            
            
$noCotizacion $_GET['noCotizacion'];
            
$cantidad $_GET['cantidad']; 
            
$descripcion $_GET['descripcion'];
            
$tiempoEntrega $_GET['tiempoEntrega']; 
            
$precioUnitario $_GET['precioUnitario']; 
            
$costoTotal $_GET['costoTotal']; 
            
            
/*
            $insertSQL2 = "INSERT INTO datoscotizacion (noCotizacion,cantidad,descripcion,tiempoEntrega,precioUnitario,costoTotal,subTotal,total) VALUES ('".$noCotizacion."',".$cantidad.",'".$descripcion."','".$tiempoEntrega."',".$precioUnitario.",".$costoTotal.");";
            
            $Result2 = mysql_query($insertSQL2) or die("no se hace el insert 2");
*/
echo "<strong>datos pasados:</strong> <br /><br />";
echo 
"noCotizacion: ".$noCotizacion."<br />";
echo 
"cantidad: ".$cantidad."<br />";
echo 
"descripcion: ".$descripcion."<br />";
echo 
"tiempoEntrega: ".$tiempoEntrega."<br />";
echo 
"precioUnitario: ".$precioUnitario."<br />";
echo 
"costoTotal: ".$costoTotal."<br />";

?><div id="loading" style="display:none;" align="left">
          <table width="50" border="1" style="border-collapse:collapse;">
            <tr>
              <td bgcolor="#FF0000"><span style="color:#FFFFFF; font-weight:bold;">Cargando...</span></td>
            </tr>
          </table>
</div>
__________________
Firma:
Es mas dificil para el mono entender que el hombre desciende de el....

PD: Siempre doy karma al que me da una buena respuesta... ;0)

Última edición por farra; 07/01/2009 a las 14:02