how can I get two date values with jQuery and send them to another document?

0
<input type="text" class="primerFecha" name="">
<input type="text" class="segundaFecha" name="">

<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
     <a id="reporteBV" target="_blank">envio</a>
</button>

//aqui quiero enviar las dos fechas

<script type="text/javascript">
 $(function(){
    $(".primeraFecha").on("change",function(){
      var valor = $(this).val();
      if (valor >=1){
        $("#reporteBV").attr("href","report/resumenventas.php?fecInicio="+valor);
      }else{
      }
    });
  });
</script>
                    
asked by alvin 04.12.2017 в 19:24
source

1 answer

1

You must bear in mind that when you use dropdown-toggle bootstrap it cancels the default behaviors of the elements, in this case of the <a> tag, then what you could do is send the variables to the required file using window.open()

$(function(){
    $("#btn_envio").click(function(){
        var primerFecha = $(".primerFecha").val();
        var segundaFecha = $(".segundaFecha").val();
      
        if (primerFecha != '' && segundaFecha != ''){
            window.open("report/resumenventas.php?fecInicio=" + primerFecha + "&fecFinal=" + segundaFecha, "_blank")
        }else{
            alert('Faltan campos por llenar');
        }
    });
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<input type="text" class="primerFecha" name="">
<input type="text" class="segundaFecha" name="">

<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" id="btn_envio">
     <a id="reporteBV" target="_blank" href="#">envio</a>
</button>

Note: SOes snippet does not work window.open() but when you do it in your local environment it will work for you.

    
answered by 04.12.2017 / 23:33
source