Ver Mensaje Individual
  #4 (permalink)  
Antiguo 05/03/2012, 15:58
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 17 años, 7 meses
Puntos: 1567
Respuesta: Mostrar el contenido de un formulario en una segunda página sin php

Un ejemplo práctico con javascript.

pasar

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>Pasar variables</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. </head>
  7.     <form action="recibir.html" method="get">
  8.         <p>nombre: <input type="text" name="nombre" value ="" /><br />
  9.             apellido: <input type="text" name="apellido" value ="" /><br />
  10.             <input type="submit" value="procesar" />
  11.         </p>
  12.     </form>
  13. </body>
  14. </html>

recibir

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>Recibe variables</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <script type="text/javascript" src="recibir_variable.js"></script>
  7. <script type="text/javascript">
  8. //<![CDATA[
  9. function escribir_valor(){
  10. var texto = "El valor para las variables nombre y apellido pasada por el form es: " + nombre + " " + apellido ;
  11. document.getElementById('mensaje').innerHTML = texto;
  12. }
  13. //]]>
  14. </head>
  15. <body onload="escribir_valor()">
  16. <div id="mensaje"></div>
  17. </body>
  18. </html>

recibir_variable.js

Código Javascript:
Ver original
  1. /* Recibir variables */
  2. /* Esta función transforma en variables cualquier parametro pasado por get /*
  3. /* Una vez llamada al inicio de la página puede recuperar el valor simplemente usando el name del input como valor */
  4. function RecibirVariablesJs(qs){
  5. var s="";
  6. for(var i=0;i<qs.length;i++){
  7. if(qs.substring(i,i+1)=="+"){
  8. s=s+" ";
  9. }else{
  10. s=s+qs.substring(i,i+1);
  11. }
  12. }
  13. return s;
  14. }
  15. var c=eval('"'+document.location+'"');
  16. var n,m,o;
  17. var variable;
  18. var valor;
  19. n=c.indexOf("?");
  20. if(n==-1){
  21.     }else{
  22.         while(n<c.length){
  23.             m=c.indexOf("=",n);
  24.             variable=c.substring(n+1,m);
  25.             o=c.indexOf("&",m);
  26.             if(o==-1){o=c.length;
  27.                 }
  28.                 valor=unescape(RecibirVariablesJs(c.substring(m+1,o)));
  29.                 eval ("var "+variable+"='"+valor+"';");
  30.                 n=o;}
  31.                 }

Otra alternativa es usando cookies

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.