-4

Is it possible to get the results of "fusiontabledata" and "fusiontabledata2", compare both and generate a third "sidebar" showing only the duplicates?

document.getElementById('sidebar_1').innerHTML = fusiontabledata;
document.getElementById('sidebar_2').innerHTML = fusiontabledata2;

function getData_From(response) {
  FTresponse = response;
  numRows = response.getDataTable().getNumberOfRows();
  numCols = response.getDataTable().getNumberOfColumns();
  fusiontabledata = "<table><tr>";
  fusiontabledata += "</tr><tr>";
  for (i = 0; i < numRows; i++) {
    for (j = 0; j < numCols; j++) {
      fusiontabledata += "<td>" + response.getDataTable().getValue(i, j) + "</td>";
    }
    fusiontabledata += "</tr><tr>";
  }
  fusiontabledata += "</table>"
  document.getElementById('sidebar_1').innerHTML = fusiontabledata;
}

function getData_To(response) {
  FTresponse = response;
  numRows = response.getDataTable().getNumberOfRows();
  numCols = response.getDataTable().getNumberOfColumns();
  fusiontabledata2 = "<table><tr>";
  fusiontabledata2 += "</tr><tr>";
  for (i = 0; i < numRows; i++) {
    for (j = 0; j < numCols; j++) {
      fusiontabledata2 += "<td>" + response.getDataTable().getValue(i, j) + "</td>";
    }
    fusiontabledata2 += "</tr><tr>";
  }
  fusiontabledata2 += "</table>"
  document.getElementById('sidebar_2').innerHTML = fusiontabledata2;
}
user35280
  • 3
  • 1
  • 3
  • Can you show us what the contents of `sidebar_1` and `sidebar_2` look like? Do you just want child elements that exist in both, shown in a third element? – Sampson Feb 23 '15 at 22:10
  • The content is text (string), i just want to compare both and show duplicates under the map. – user35280 Feb 23 '15 at 22:17
  • 2
    Duplicates of what? Words? Characters? Can you show an example of two elements (with their text) and the third element with the common contents? – Sampson Feb 23 '15 at 22:19

1 Answers1

1

innerHTML is a string, you may easily compare both strings.

Do it at the end of both functions, when the strings are equal, add the results to the 3rd sidebar:

if(document.getElementById('sidebar_1').innerHTML 
    === 
   document.getElementById('sidebar_2').innerHTML){
   document.getElementById('sidebar_3')
    .appendChild(document.getElementById('sidebar1')
                  .firstChild.cloneNode(true));
}
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201
  • That worked when comparing the whole 'sidebar' but i still dont know how to compare each individual "response.getDataTable().getValue(i, j)" of fusiontable 1 and 2. – user35280 Feb 24 '15 at 16:40
  • How do you run the requests? Will there be multiple requests for each sidebar? Please explain the workflow of your application. – Dr.Molle Feb 24 '15 at 16:53
  • I use a function: codeadress() that calls creatsidebar(lat,lng) and this creatsidebar has: queryText = encodeURIComponent("select .... query = new google.visualization.Query.... query.send(getData_From); – user35280 Feb 24 '15 at 17:09
  • you create both sidebars(and start 2 requests) in codeAddress? When you run codeAddress multiple times, will the previous sidebars be discarded? – Dr.Molle Feb 24 '15 at 18:47
  • yes, they change if you type another address and click the seach button – user35280 Feb 24 '15 at 19:17