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

Asked

Viewed 70 times

3

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

So, I have a start date and an end date, and within these two dates he searches a table within his trs and tds such dates that will be in this range.

The functions used to make this range (which is gurdado 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 takes place that triggers 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));
    });

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));

});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.