Foros del Web » Programando para Internet » Javascript »

Imprimir y guardar formulario con un solo botón.

Estas en el tema de Imprimir y guardar formulario con un solo botón. en el foro de Javascript en Foros del Web. Hola amigos, estoy aquí de nuevo pidiendo vuestra ayuda, ojala puedan ayudarme :D. Mi problema es el siguiente, estoy tratando de guardar e imprimir a ...
  #1 (permalink)  
Antiguo 10/06/2011, 17:08
 
Fecha de Ingreso: julio-2010
Ubicación: Chillan, Chile
Mensajes: 60
Antigüedad: 13 años, 9 meses
Puntos: 1
Pregunta Imprimir y guardar formulario con un solo botón.

Hola amigos, estoy aquí de nuevo pidiendo vuestra ayuda, ojala puedan ayudarme :D.
Mi problema es el siguiente, estoy tratando de guardar e imprimir a la ves un formulario con un solo botón.
La primera parte de guardar los datos del formulario la tengo solucionada.
La parte de la impresión es en la que tengo problemas, pues me gustaria imprimir solamente el formulario y no el botón para esta acción, pero ocurre todo lo contrario jejeje.
Me apoye en en la FAQ 178 http://www.forosdelweb.com/f13/faqs-...tml#post629887.

mi codigo es el siguiente:


Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Documento sin título</title>
  5. <style type="text/css">
  6. @media print {
  7.     div,a {display:none}
  8.     .ver {display:block}
  9.     .nover {display:none}
  10. }
  11. #centrar {
  12.     text-align: center;
  13. }
  14.  
  15. <script language="javascript">
  16.  
  17. function ocultaBoton(){
  18.     var oculto= document.getElementById("hiddenField").value;
  19.     alert("oculto vale : "+oculto);
  20.     if(oculto==1){
  21.         document.getElementById("hiddenField").value=0;
  22.         return true;
  23.     }
  24.         return false;
  25. }
  26.  
  27. function SumaOtros(){
  28.     var valor_consumo=parseInt(document.form1.valor_consumo.value);
  29.     var subsidio=parseInt(document.form1.subsidio.value);
  30.     var deuda_anterior=parseInt(document.form1.deuda_anterior.value);
  31.     var otros=parseInt(document.form1.otros.value);
  32.     var otros2=parseInt(document.form1.otros2.value);
  33.     //Compruebo si es un valor numérico
  34.     if (isNaN(otros2)) {
  35.        //entonces (no es numero) devuelvo el valor cadena vacia
  36.        alert("Debe ingresar un numero entero");
  37.        return "" ;
  38.     }
  39.     var total;
  40.     total=valor_consumo - subsidio + deuda_anterior + otros + otros2;
  41.    
  42.     document.getElementById("total").value= total;
  43.    
  44. }
  45.  
  46. function impre(num) {
  47.     document.getElementById(num).className="ver";
  48.     print();
  49.     document.getElementById(num).className="nover";
  50. }
  51. </head>
  52. <?php
  53.  
  54. $nombres=$_REQUEST['nombres'];
  55. $apellidos=$_REQUEST['apellidos'];
  56. $numero_socio=$_REQUEST['numero_socio'];
  57. $numero_cuenta=$_REQUEST['numero_cuenta'];
  58. $direccion_cuenta=$_REQUEST['direccion_cuenta'];
  59.  
  60. include("../../../Persistencia/DAO/ConsumoDAO.php");
  61. $consumo_dao=new ConsumoDAO;
  62. $ultimo_aviso=$consumo_dao->get_ultimo_aviso_cuenta($numero_cuenta);
  63. $aviso_cuenta=mysql_fetch_array($ultimo_aviso);
  64.  
  65.  
  66. ?>
  67. <form id="centrar" name="form1" method="post" target="guardador" action="../../../Persistencia/Controlador/pagos/guardarBoletaControlador.php?" onSubmit="return ocultaBoton()">
  68.   <div id="uno">
  69.   <table width="620" border="1" align="center" >
  70.     <tr>
  71.       <th width="65%"colspan="2" bgcolor="#33CCFF"><p>Cooperativa de servicio de agua Potable Quiriquina Ltda., Captacion,Purificación y Distribución de Agua.</p></th>
  72.       <th colspan="2" bgcolor="#33CCFF" >Boleta de venta y servicio no afectos o exentos de iva.</th>
  73.     </tr>
  74.     <tr>
  75.       <td width="122" bgcolor="#00FFCC"><strong>Nombre</strong></td>
  76.       <td width="228" ><label>
  77.         <input name="nombres" type="text" id="nombres" value="<?php echo $nombres." " .$apellidos?>" size="40" readonly="readonly" />
  78.       </label></td>
  79.       <td width="113" bgcolor="#00FFCC">N° Socio</td>
  80.       <td width="129"><label>
  81.         <input name="numero_socio" type="text" id="numero_socio" value="<?php echo $numero_socio ?>" size="15" readonly="readonly" />
  82.       </label></td>
  83.     </tr>
  84.     <tr>
  85.       <td height="23" bgcolor="#00FFCC"><strong>Dirección</strong></td>
  86.       <td height="23"><label>
  87.         <input name="direccion" type="text" id="direccion" value="<?php echo $direccion_cuenta?>" size="40" readonly="readonly" />
  88.       </label></td>
  89.       <td bgcolor="#00FFCC">N° Cuenta</td>
  90.       <td><label>
  91.         <input name="numero_cuenta" type="text" id="numero_cuenta" value="<?php echo $numero_cuenta?>" size="15" readonly="readonly" />
  92.       </label></td>
  93.     </tr>
  94.   </table>
  95.   <table width="620" border="1" align="center">
  96.     <tr bordercolor="#FF6600">
  97.       <td width="25%" align="center" bgcolor="#FF6600">Consumo</td>
  98.       <td width="25%" align="center" bgcolor="#FF6600">L.Actual.</td>
  99.       <td width="25%" align="center" bgcolor="#FF6600">L. Anterior</td>
  100.       <td width="25%" align="center" bgcolor="#FF6600">Mes Consumo</td>
  101.     </tr>
  102.     <tr>
  103.       <td height="23"><label>
  104.         <input name="consumo" type="text" id="consumo" value="<?php echo $aviso_cuenta[metros_consumidos]?>" size="18" readonly="readonly" />
  105.       </label></td>
  106.       <td><label>
  107.         <input name="lectura_actual" type="text" id="lectura_actual" value="<?php echo $aviso_cuenta[lectura]?>" size="18" readonly="readonly" />
  108.       </label></td>
  109.       <td><label>
  110.         <input name="lectura_anterior" type="text" id="lectura_anterior" value="<?php echo $aviso_cuenta[lectura]-$aviso_cuenta[metros_consumidos]?>" size="18" readonly="readonly" />
  111.       </label></td>
  112.       <td><label>
  113.         <input name="mes_consumo" type="text" id="mes_consumo" value="<?php echo $aviso_cuenta[periodo_pago]?>" size="18" readonly="readonly" />
  114.       </label></td>
  115.     </tr>
  116.   </table>
  117.   <table width="620" border="1" align="center">
  118.     <tr bgcolor="#66CC66">
  119.       <td height="23" align="center" ><strong>Detalle</strong></td>
  120.       <td width="140" ><strong>Valor</strong></td>
  121.     </tr>
  122.     <tr>
  123.       <td width="80%">(+) Valor consumo mensual</td>
  124.       <td><label>
  125.         <input name="valor_consumo" type="text" id="valor_consumo" value="<?php echo $aviso_cuenta[valor]?>" readonly="readonly" />
  126.       </label></td>
  127.     </tr>
  128.     <tr>
  129.       <td height="23">(-) Subsidio</td>
  130.       <td><label>
  131.         <input name="subsidio" type="text" id="subsidio" value="<?php echo $aviso_cuenta[subsidio]?>" readonly="readonly" />
  132.       </label></td>
  133.     </tr>
  134.     <tr>
  135.       <td height="23">(+) Deuda anterior</td>
  136.       <td><label>
  137.         <input name="deuda_anterior" type="text" id="deuda_anterior" value="<?php echo $aviso_cuenta[deuda_anterior]?>" readonly="readonly" />
  138.       </label></td>
  139.     </tr>
  140.     <tr>
  141.       <td height="23">(+) Otros : <?php if($aviso_cuenta[otros]==0){echo "no registra otras deudas";}else{echo $aviso_cuenta[motivo_otros];}?></td>
  142.       <td><input name="otros" type="text" id="otros" value="<?php echo $aviso_cuenta[otros]?>" readonly="readonly" /></td>
  143.     </tr>
  144.     <tr>
  145.       <td height="23" align="left">( + )Otro motivo:
  146.         <label>
  147.           <input name="otro_motivo" type="text" id="otro_motivo" size="49" />
  148.       </label></td>
  149.       <td><label>
  150.         <input type="text" name="otros2" id="otros2" onblur="SumaOtros()" />
  151.       </label></td>
  152.     </tr>
  153.     <tr>
  154.       <td height="23" align="center" bgcolor="#66CC66"><strong>Total</strong></td>
  155.       <td ><label>
  156.       <input type="text" name="total" id="total" value="<?php //(+)valor mensual(-)subsidio(+)deuda anterior(+)otros
  157.       echo $valor_total=$aviso_cuenta[valor]-$aviso_cuenta[subsidio]+$aviso_cuenta[deuda_anterior]+$aviso_cuenta[otros];?>"/>
  158.       </label></td>
  159.     </tr>
  160.     <tr>
  161.       <td height="23" colspan="3" align="left">N° Boleta : <?php echo $numero_boleta?></td>
  162.     </tr>
  163.   </table>
  164.   </div>
  165.   <input type="submit" name="guardar_imprimir" id="guardar_imprimir" value="   Imprimir - Guardar   " onclick "impre('uno');return false"/>
  166. </form>
  167.  
  168. <input type="hidden" name="hiddenField" id="hiddenField" value="1"/>
  169. <!-- el iframe permite que al enviar el formulario a la otra pagina los datos del formulario se guarden en la base de datos, pero con el atributo target se le indica que sea rederigido a el <iframe>.
  170. -->
  171. <iframe name="guardador" id="guardador" height="10" frameborder="0" width="0" >
  172. </body>
  173. </html>

De antemano a quienes puedan ayudarme muchas gracias. :D

Última edición por kryzpo23; 10/06/2011 a las 18:10
  #2 (permalink)  
Antiguo 10/06/2011, 21:10
 
Fecha de Ingreso: julio-2010
Ubicación: Chillan, Chile
Mensajes: 60
Antigüedad: 13 años, 9 meses
Puntos: 1
Respuesta: Imprimir y guardar formulario con un solo botón.

ya esta resuelto, es el boton el que debe ir dentro del div y no la tabla que quiero imprimir.

Etiquetas: formulario
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 08:10.