Foros del Web » Programando para Internet » Javascript »

[SOLUCIONADO] Pasar datos de una ventana hija (modal) a ventana padre js

Estas en el tema de Pasar datos de una ventana hija (modal) a ventana padre js en el foro de Javascript en Foros del Web. Hola a todos tengo un script padre en el cual abro una ventana emergente y capturo algunos datos, los cuales quiero regresar al script padre ...
  #1 (permalink)  
Antiguo 28/08/2013, 12:42
 
Fecha de Ingreso: julio-2013
Mensajes: 32
Antigüedad: 10 años, 8 meses
Puntos: 2
Pasar datos de una ventana hija (modal) a ventana padre js

Hola a todos tengo un script padre en el cual abro una ventana emergente y capturo algunos datos, los cuales quiero regresar al script padre ¿como puedo hacerlo?

He estado investigando y me encontré que tambien se puede hacer con window.open sin embargo no encuentro la forma de ocultar la barra de dirección ya he probado con:

location=no
location=0

perro me la sigue mostrando es por eso que opte x utilizar modal pero con modal no se como mandar los datos al script padre.

ayuda xfavor.
  #2 (permalink)  
Antiguo 29/08/2013, 11:07
Colaborador
 
Fecha de Ingreso: mayo-2008
Ubicación: $MX['VZ']['Xalapa']
Mensajes: 3.005
Antigüedad: 15 años, 11 meses
Puntos: 528
Respuesta: Pasar datos de una ventana hija (modal) a ventana padre js

Una ventana "modal" no es una ventana propiamente si no una capa dentro de la ventana principal. Si es así, los datos que pudiera tener una ventana modal ya están dentro de la padre.

Si muestras tu script y los datos que quieres capturar de la ventana modal se te podría orientar.
  #3 (permalink)  
Antiguo 29/08/2013, 14:53
 
Fecha de Ingreso: julio-2013
Mensajes: 32
Antigüedad: 10 años, 8 meses
Puntos: 2
Respuesta: Pasar datos de una ventana hija (modal) a ventana padre js

Hola ocp001a tengo estos 2 archivos
Este es el script padre que al presionar algún input de telefono manda llamar al script hijo en el cual respecto a una serie de validaciones puedo capturar en un input el número telefónico y ese número telefónico necesito regresarlo al al input del script padre lo cual hago con la funcion insertar, todo funciona bien con window open pero quisiera saber como hacerlo con window.showModalDialog

Código HTML:
Ver original
  1.     <head>
  2.             <TITLE>DIALER - MODO PREDICTIVO</TITLE>
  3.     </head>
  4.        
  5. <script language=javascript>
  6. function validar_telefono(id){
  7.     window.showModalDialog("validar_telefono.html?id="+id,window.document,"center=yes;dialogheight=410px;dialogwidth=360px;");
  8. }
  9. <BODY BGCOLOR="white" TEXT="#2000A0" STYLE="font-family: ARIAL,HELVETICA,SANS-SERIF">
  10. <form action="" method="post" name="form" id="form">
  11.  
  12. <div id="formulario" name="Formulario">    
  13.        
  14.         <table border='0'style="background-color: WHITE; WIDTH:150px; margin-left: -10px;" >
  15.         <tr>
  16.             <td style="color: black; font-family: Arial; width: 80px;font-size:14px;" ><small>Telefono 1: </small></td>
  17.             <td > <input id="Telefono1" name="Telefono1" value="" type="text"  onchange=" " size="12" style="font-family: Arial; font-size: 8pt;height: 16px;" onDblClick="validar_telefono('Telefono1');" readonly></td>
  18.             <td style="color: black; font-family: Arial; font-size:14px;"><small>Telefono 2: </small></td>
  19.             <td> <input id="Telefono2" name="Telefono2" value="" type="text"  onchange=" " size="12" style="font-family: Arial; font-size: 8pt;height: 16px;" onDblClick="validar_telefono('Telefono2');" readonly></td>
  20.         </tr>
  21.         <tr>
  22.             <td style="color: black; font-family: Arial; width: 80px; font-size:14px;"><small>Telefono 3: </small></td>
  23.             <td > <input id="Telefono3" name="Telefono3" value="" type="text"  onchange=" " size="12" style="font-family: Arial; font-size: 8pt;height: 16px;" onDblClick="validar_telefono('Telefono3');" readonly></td>
  24.             <td style="color: black; font-family: Arial; font-size:14px;"><small>Telefono 4: </small></td>
  25.             <td> <input id="Telefono4" name="Telefono4" value="" type="text"  onchange=" " size="12" style="font-family: Arial; font-size: 8pt;height: 16px;" onDblClick="validar_telefono('Telefono4');" readonly></td>
  26.         </tr>
  27.     </form>
  28.     </table>
  29. <iframe name="trastero" style="width:0px;height:0px;visibility:hidden"></iframe>
  30. </div>
  31. </Body>
  32. </HTML>

script hijo

Código HTML:
Ver original
  1.     <head>
  2.             <TITLE>Cliente Scripter</TITLE>
  3.     </head>
  4.     <script language=javascript>
  5.    
  6.     query=window.location.search.substring(1);
  7.     q=query.split("="); //clienteid=123456789,valor=opcion1
  8.     var id =q[1];
  9.      document.getElementById("LargaDistancia").style.display = 'none';
  10.      
  11.      function larga_distancia(){
  12.          document.getElementById("Tel_completo").disabled=true;
  13.          document.getElementById("LargaDistancia").style.display = '';
  14.          document.getElementById("Local").style.display = 'none';
  15.          document.getElementById("Tel").value='';
  16.          document.getElementById("Tel_completo").value='';
  17.      }
  18.      
  19.      function local(){
  20.          document.getElementById("Tel_completo").disabled=true;
  21.          document.getElementById("LargaDistancia").style.display = 'none';
  22.          document.getElementById("Local").style.display = '';
  23.          document.getElementById("Tel").value='';
  24.          document.getElementById("Tel_completo").value='';
  25.      }
  26.      function ld_fijo(){
  27.          document.getElementById("Tel_completo").disabled=false;
  28.          var input = document.getElementById ("Tel_completo");
  29.          input.maxLength = 10;
  30.          document.getElementById("Tel").value='901';
  31.          document.getElementById("num_caracteres").value= 10;
  32.          document.getElementById("Tel_completo").value='';
  33.          document.getElementById('Tel_completo').focus();
  34.      }
  35.      
  36.      function ld_movil(){
  37.          document.getElementById("Tel_completo").disabled=false;
  38.          var input = document.getElementById ("Tel_completo");
  39.          input.maxLength = 10;
  40.          document.getElementById("Tel").value='9045';
  41.          document.getElementById("num_caracteres").value= 10;
  42.          document.getElementById("Tel_completo").value='';
  43.          document.getElementById('Tel_completo').focus();
  44.      }
  45.      
  46.      function loc_fijo(){
  47.          document.getElementById("Tel_completo").disabled=false;
  48.          var input = document.getElementById ("Tel_completo");
  49.          input.maxLength = 8;
  50.          document.getElementById("Tel").value='9';
  51.          document.getElementById("num_caracteres").value= 8;
  52.          document.getElementById("Tel_completo").value='';
  53.          document.getElementById('Tel_completo').focus();
  54.      }
  55.      
  56.      function loc_movilFijo(){
  57.          document.getElementById("Tel_completo").disabled=false;
  58.          var input = document.getElementById ("Tel_completo");
  59.          input.maxLength = 10;
  60.          document.getElementById("Tel").value='9044';
  61.          document.getElementById("num_caracteres").value= 10;
  62.          document.getElementById("Tel_completo").value='';
  63.          document.getElementById('Tel_completo').focus();
  64.      }
  65.      
  66.      function insertar(){
  67.       var ret = validar_num_caracteres();
  68.       if (ret != false){
  69.           if(confirm("El número " + document.getElementById("Tel").value + document.getElementById("Tel_completo").value + " ¿es correcto?")){
  70.               window.opener.document.getElementById(id).value = document.getElementById("Tel").value + document.getElementById("Tel_completo").value;
  71.               window.close();
  72.           }
  73.       }
  74.      }
  75.      
  76.      function validar_num_caracteres() {
  77.          var num_caracteres = document.getElementById("num_caracteres").value;
  78.           if (form.Tel_completo.value.length < num_caracteres) {
  79.             alert('El número de no puede contener menos de ' + num_caracteres + " caracteres." );
  80.             form.Tel.focus();
  81.             return false;
  82.           }
  83.         }
  84.      function validarNro(e) //Esta funcion valida que solo se acepten números donde corresponda.
  85.      {
  86.         var key;
  87.                 if(window.event)
  88.                     {
  89.                     key = e.keyCode;
  90.                     }
  91.                 else if(e.which)
  92.                     {
  93.                     key = e.which;
  94.                     }
  95.                
  96.                 if (key < 48 || key > 57)
  97.                     {
  98.                     if(key == 46 || key == 8)
  99.                         { return true; }
  100.                     else
  101.                         { return false; }
  102.                     }
  103.                 return true;
  104.      } 
  105.      
  106.      function cancelar(){
  107.          window.close();
  108.      }
  109.      
  110.     </script>
  111. <BODY BGCOLOR="white" TEXT="#2000A0" STYLE="font-family: ARIAL,HELVETICA,SANS-SERIF">
  112. <form id="form" method="post" action="" id="form">
  113. <center style="color: black; font-family: Arial;"><h3>Tipo de teléfono</h3></center>
  114. <table align="center">
  115.   <tr>
  116.       <td style="color: black; font-family: Arial;"><input type="radio" name="myradio" value="Desabasto" onClick="larga_distancia();">Larga Distancia </td>    
  117.       <td style="color: black; font-family: Arial;"><input type="radio" name="myradio" value="No le interesa" onClick="local();">Local</td>
  118.       <td style="color: black; font-family: Arial;" height="10"></td>      
  119.     </tr>
  120. <div id="LargaDistancia" style="display:none;"  name="LargaDistancia">
  121. <table align="center">
  122.     <tr>
  123.         <td style="color: black; font-family: Arial;"><input type="radio" name="myradio_2" value="Baja rotacion" onClick="ld_fijo();">Teléfono fijo</td>       
  124.         <td style="color: black; font-family: Arial;"><input type="radio" name="myradio_2" value="No esta en portafolio" onClick="ld_movil();">Teléfono movil</td>
  125.         <td style="color: black; font-family: Arial;" height="10"></td>            
  126.     </tr>
  127. </div>
  128. <div id="Local" style="display:none;"  name="Local">
  129. <table align="center">
  130.     <tr>
  131.         <td style="color: black; font-family: Arial;"><input type="radio" name="myradio_2" value="Baja rotacion" onClick="loc_fijo();">Teléfono fijo</td>      
  132.         <td style="color: black; font-family: Arial;"><input type="radio" name="myradio_2" value="No esta en portafolio" onClick="loc_movilFijo();">Movil fijo</td>
  133.         <td style="color: black; font-family: Arial;" height="10"></td>        
  134.     </td>              
  135.     </tr>
  136. </div>
  137. <center>
  138.   <input id="Tel" name="Tel" value="" type="text"  size="12" style="font-family: Arial; font-size: 8pt;height: 16px; border:none;" disabled onkeypress="javascript:return validarNro(event)">
  139.   <input id="Tel_completo" name="Tel_completo" value="" type="text"  size="12" style="font-family: Arial; font-size: 8pt;height: 16px; " disabled onkeypress="javascript:return validarNro(event)">
  140.   <input id="num_caracteres" name="num_caracteres" value="" type="hidden"  size="12" style="font-family: Arial; font-size: 8pt;height: 16px;" >
  141.   <br>
  142.   <br>
  143.   <input type="button" value="Guardar" onClick="insertar();" style="WIDTH: 125px; HEIGHT: 25px">
  144.   <input type="button" value="Cancelar" onClick="cancelar();" style="WIDTH: 125px; HEIGHT: 25px">
  145. </center>
  146.  
  147. </form>    
  148. </Body>
  149. </HTML>


Gracias por anticipado =)
  #4 (permalink)  
Antiguo 03/09/2013, 14:40
 
Fecha de Ingreso: julio-2013
Mensajes: 32
Antigüedad: 10 años, 8 meses
Puntos: 2
Respuesta: Pasar datos de una ventana hija (modal) a ventana padre js

Hola despues de buscar en varios lados encontre la solución por si le sirve a alguien aki se las pongo:

Debo mencionar que esta opción solo funciona en Internet explorer.

Modal1.htm

Código HTML:
Ver original
  1. <head><title>Demo modal dialog</title></head>
  2. <script language="JavaScript">
  3. function changeMe(szName)
  4. {
  5.     var szUrl;
  6.     var szFeatures;
  7.  
  8.     szUrl = 'modal2.htm';
  9.     szFeatures = 'dialogWidth:20; dialogHeight:10; status:0; help:0';
  10.  
  11.     szName = window.showModalDialog(szUrl, szName, szFeatures)
  12.     Name.innerText = szName;
  13. }
  14. <p>Hello, your name is <b><span id="Name">Unknown</span></b>.</p>
  15. <p><input type="button" onClick="changeMe(Name.innerText)" value="Change Name"></p>
  16. </body>
  17. </html>

Modal2.htm

Código HTML:
Ver original
  1. <head><title>Enter your name</title></head>
  2. <script language="JavaScript" for="window" event="onLoad">
  3.     Name.value = window.dialogArguments;
  4. <script language="JavaScript">
  5. function closeMe()
  6. {
  7.     window.returnValue = Name.value;
  8.     event.returnValue = false;
  9.     window.close();
  10. }
  11. <p><input type="text" name="Name" value=""></p>
  12. <p><input type="button" value="Submit" onClick="closeMe()"></p>
  13. </body>
  14. </html>

Etiquetas: hija, js, modal, padre, ventana
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:16.