How to pass a variable js to a query in ASP.Net

0

Very well I explain, I have a form, I use the date picker range for the dates, and it works, I make a console.log and it gives me the start date and the end, all right up there, the point now is like I send that variable to my search query in the ASP.

$(function () {
                   $('input[name="daterange"]').daterangepicker({
                       opens: 'left'
                   }, function (start, end, label) {
                       //console.log("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));

                     //Estas son las 2 variables que quiero enviar por separado
                       var finicio = start.format('YYYY-MM-DD');
                       var ffinal = end.format('YYYY-MM-DD');

                   });
               });

This is the query as you see I need the start and end date to filter:

where b.fecha_ef>='2018-09-01' and b.fecha_ef<='2018-09-30'

But the point is how do I put my variables, something like that?

where b.fecha_ef>=finicio and b.fecha_ef<=ffinal

I would really appreciate it, it's been a while now: /

The date selection input:

<input type="text" name="daterange" class="form-control" value="11/09/2018 - 11/30/2018" />
    
asked by Jonathan 11.12.2018 в 20:00
source

1 answer

1

One solution could be to create two hidden fields and enter the values that the datapicker returns to them.

This way, then if you could retrieve the values from vb and put them in the query.

We would create the hidden ones:

<input type="hidden" name="hidFechaDesde"  id="hidFechaDesde" value="" />
<input type="hidden" name="hidFechaHasta"  id="hidFechaHasta" value="" />

We would retrieve the datepicker value in these variables:

() {

$ ('input [name="daterange"]'). daterangepicker ({        opens: 'left'    }, function (start, end, label) {        //console.log("A new date selection was made: "+ start.format ('YYYY-MM-DD') + 'to' + end.format ('YYYY-MM-DD'));

 //Estas son las 2 variables que quiero enviar por separado
   var finicio = start.format('YYYY-MM-DD');
   var ffinal = end.format('YYYY-MM-DD');

   $('#hidFechaDesde').val(finicio);
   $('#hidFechaHasta').val(ffinal);

}); });

and later we could recover the value of the hidden in the query:

" where b.fecha_ef>='" & Request.form("hidFechaDesde") & "' and b.fecha_ef<='" & Request.form("hidFechaHasta") & "' "

I hope it serves you.

Greetings

    
answered by 13.12.2018 / 10:32
source