0

Con este codigo solamente se muestran dos input para que se pueda colocar una fecha, conforme a esa fecha y el boton de consultar se va a redirigir al archivo reporte. php que es un archivo en donde se muestra una tablas con informacion filtrada por los inputs de las fechas y va junto con las variables de la fecha. cuando hace las validaciones para verificar si estan vacias si funcionan y muestra la alerta pero cuando todo esta bien e intento hacer la consulta no hace nada, como que el boton funcionara

<?php $connect = mysqli_connect("localhost","root","","bd_mantenimiento"); ?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        
         <script>
            $(function () {
                $.datepicker.regional['es'] = {
                    closeText: 'Cerrar',
                    prevText: '<Ant',
                    nextText: 'Sig>',
                    currentText: 'Hoy',
                    monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
                    monthNamesShort: ['Ene','Feb','Mar','Abr', 'May','Jun','Jul','Ago','Sep', 'Oct','Nov','Dic'],
                    dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
                    dayNamesShort: ['Dom','Lun','Mar','Mié','Juv','Vie','Sáb'],
                    dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sá'],
                    weekHeader: 'Sm',
                    dateFormat: 'dd/mm/yy',
                    firstDay: 1,
                    isRTL: false,
                    showMonthAfterYear: false,
                    yearSuffix: ''
                };
                $.datepicker.setDefaults($.datepicker.regional['es']);
                $(function () {
                    $("#fecha_i").datepicker({minDate: "", maxDate: "+0D"});
                    $("#fecha_f").datepicker({ minDate: "", maxDate: "+0D" });
                });
            });
          </script>
          
          
          <script>
              function consultar_reporte(){
                  var  fecha_inicio, fecha_final, fecha_i, fecha_f, fechai, fechaf;
                                           
                  fecha_inicio = document.getElementById('fecha_i').value;
                  fecha_final = document.getElementById('fecha_f').value;
                  
                  
                  
                  if( fecha_inicio == "" || fecha_final == "" ){
                      alert("TODOS LOS CAMPOS SON OBLIGATORIOS");
                  }
                  else{                      
                      fecha_inicio = fecha_inicio.split("/");
                      fecha_i = new Date(fecha_inicio[2], fecha_inicio[1] - 1, fecha_inicio[0]);       
                      fechai = fecha_inicio[2] + "-" + fecha_inicio[1] + "-" + fecha_inicio[0];
                      fecha_final = fecha_final.split("/");
                      fechaf = fecha_final[2] + "-" + fecha_final[1] + "-" + fecha_final[0];
                      fecha_f = new Date(fecha_final[2], fecha_final[1] - 1, fecha_final[0]);
                      if(parseInt(fecha_i.getTime()) > parseInt(fecha_f.getTime())){
                          alert("LA FECHA INICIAL DEBE SER MENOR A LA FECHA FINAL");
                      }
                      else{
                          
                           document.getElementById('contenido2').innerHTML="<img src='ejemplo/img/loading.gif' height='6%' width='6%' alt='' />";
                           //$("#contenido2").load("formularios/cons_ord_x_serv.php?fecha_i="+fechai+"&fecha_f="+fechaf+"&op="+opcion+"&op2="+opcion2);
                           $("#contenido2").load("reporte.php?fecha_i="+fechai+"&fecha_f="+fechaf);
                      }
                  }
              }
          </script>
          
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        // put your code here
        
        ?>
        <input type="text" name="codigo" id="codigo" hidden/>     
        <table  style=" background-color:  #DDDDDD">
            <thead>
                <tr>
                    <th>
                        <br>
                        <label style='text-align: center; font-size: 125%'>
                             Reporte General</label>
                        <br>
                        <br>
                    </th>
                </tr>
            </thead>
            <tbody>                
                <tr>
                    <td>                     
                        <label>FECHA INICIAL:</label>
                        <input type="text" name="fecha_i" id="fecha_i" size="8" /> 
                        
                        <label>FECHA FINAL:</label>
                        <input type="text" name="fecha_f" id="fecha_f" size="8" />
                        
                       <!-- <input type="radio" name="opcion" value="generada" checked>Generadas
                        <input type="radio" name="opcion" value="pendiente" >Pendientes
                        <input type="radio" name="opcion" value="cerrada"  >Cerradas
                        <br>
                        <br>
                        <label>Mantto.:</label>
                        <input type="radio" name="opcion2" value="todas" checked >Todas
                        <input type="radio" name="opcion2" value="correctivo"  >Correctivo
                        <input type="radio" name="opcion2" value="preventivo"  >Preventivo-->
                     
                                   
                               
                        
                        <input type="button" value="CONSULTAR" style=" float: right"
                               onclick="consultar_reporte()" />
                        <br>
                        <br>
                    </td>
                </tr>
            </tbody>
            <tfoot>
                
            </tfoot>           
        </table>
        
    </body>
</html>
4
  • Veo que usas lo que parece jQuery, pero no veo que cargues jQuery por ningún lado ¿cómo demonios esperas que funcione entonces? el 8 dic. 2021 a las 13:49
  • lo añadi y nada: <script type="text/javascript" src="./recursos/js/jquery-1.11.1.min.js"></script> <script type="text/javascript" src="./recursos/js/jquery-ui-1.11.2.min.js"></script> <script type="text/javascript" language="javascript" src="./recursos/js/jquery.dataTables.js"></script> <script type="text/javascript" src="./recursos/js/funciones.js"></script>
    – Luis Oliva
    el 8 dic. 2021 a las 14:09
  • Mira la consola del navegador tras pulsar el botón, a ver si recoge algún error concreto. Puedes abrirla con Ctrol + Shift + J. el 8 dic. 2021 a las 14:13
  • frmo_index.php:70 Uncaught TypeError: Cannot set properties of null (setting 'innerHTML') at consultar_reporte (frmo_index.php:70) at HTMLInputElement.onclick (frmo_index.php:118)
    – Luis Oliva
    el 8 dic. 2021 a las 14:18

1 respuesta 1

1

Obtienes este error:

frmo_index.php:70 Uncaught TypeError: Cannot set properties of null (setting 'innerHTML') at consultar_reporte (frmo_index.php:70) at HTMLInputElement.onclick (frmo_index.php:118)

Que corresponde a esta instrucción:

document.getElementById('contenido2').innerHTML="<img src='ejemplo/img/loading.gif' height='6%' width='6%' alt='' />";

Y te está diciendo que no puede establecer ninguna propiedad a algo que es null. Osea, document.getElementBy('contenido2') no te está devolviendo un elemento, sino null, y es porque no hay ningún elemento identificado por 'contenido2' en tu HTML.

Añade ese elemento, por ejemplo justo tras cerrar la tabla, pon esto:

<div id="contenido2"></div>

Deberías ser capaz de depurar y solventar este tipo de errores por ti mismo.

Espero que te funcione, ánimo :)

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.