Using javascript array inside $ ("tr: contains ('" + array + "')")

3

I have 3 functions, to do the date range filter in a range of 2.

So, I have a start date and an end date, and within those two dates it looks for a table within its three and all dates that will be in that range.

The functions used to make this range (which is gurdated in an array):

// prototype of dates
Date.prototype.addDays = function(days) {
    var dat = new Date(this.valueOf())
    dat.setDate(dat.getDate() + days);
    return dat;
}

//GET DATES INTERVAL FUNCTION
function getDates(startDate, stopDate) {
    var dateArray = new Array();
    var currentDate = startDate;
    while (currentDate <= stopDate) {
        dateArray.push( new Date (currentDate) )
        currentDate = currentDate.addDays(1);
    }
    return dateArray;
}

And here where the change occurs that triggered these functions and within it I want you to look for that range of dates that I need:

$("#start").keydown(function(event) {

        var d1 = new Date($(this).val());
        var d2 = new Date($("#end").val());

        console.log(getDates(d1,d2));
    });

    $("#end").keydown(function(event) {

        var d1 = new Date($("#start").val());
        var d2 = new Date($(this).val());

        console.log(getDates(d1,d2));
    });
    
asked by anonymous 05.01.2017 / 14:25

1 answer

0

Solution:

//GET DATES INTERVAL FUNCTION
function getDates(startDate, stopDate) {
var dateArray = new Array();

var currentDate = startDate;

while (currentDate <= stopDate) {

  var newDate = currentDate;

  var res = newDate.toString().split('-');

  res = res[0].toString().split(' ');
  res = res[2] + '/' + monthToNumber(res[1]) + '/' + res[3];

  dateArray.push( res );

  currentDate = currentDate.addDays(1);

}

return dateArray;
}

$("#start").keydown(function(event) {

    var d1 = new Date($(this).val());


    var d2 = new Date($("#end").val());

    console.log(getDates(d1,d2));

});

$("#end").keydown(function(event) {

    var d1 = new Date($("#start").val());
    var d2 = new Date($(this).val());

    console.log(getDates(d1,d2));

});
    
27.01.2017 / 16:31