RESOLVED Confused on the wiki viewer building search results

I’ve been moving through the course at a pretty good pace, but when i got to the wiki viewer asignment for some reason that all changed. It has been one struggle after another with this one. Please i’m not looking for an answer i want ot beat this SOB on my own. but if you could please point me in the right direction I would be very happy!
here is my code: ( forgive the style i have only worked on features thus far )

Some ofthe problems i’m having:

  1. some but not all queries will return multiple results but when you click on them they all link to the page that the first result should link to. ( searching “dog” always seems to cause this while “cat” almost never causes it )
  2. I have a loop that should clear out all results if a new search is made but instead it just adds the new search to the bottom of the list.

Thanks again for any pointers you can share with me :slight_smile:

Are you particular about using the while method to remove results of previous searches…? I can understand the logic that you’re trying to execute i.e. when a first child exists the value will return true and the while loop will execute to remove the first child until all results are emptied. I can not find what’s really wrong as I am not that experienced with those methods. But if you want a simpler method, try using the .empty() method on your div that holds the search results instead.

1 Like
var list = document.getElementById("searchResults"); 
while(list.hasChildNodes()) {

I used the same logic, but different methods, and it worked. Will try to find out why yours did not work when I get back. Or you can share with me if you do find it first.

1 Like

Awesome Thanks for the response! i switched the while loop out for empty() as suggested. This seems like the “official” way to handle it and it works great! THANKS! I’m still having issues with search results not linking as they should.

You’re welcome :slight_smile: I noticed that the links lead to the wrong page only when the article you’re clicking has a space in them. What’s happening is that if you click on Dog Tag, what comes after the space is eliminated and you’re taken to the page ‘Dog’.

1 Like

Holy bacon bits Batman you are a genius!!! How did i not catch that?? That has to be a huge clue :slight_smile:

1 Like

The problem with my code was that when creating the links in the result i was building the links like: “” + json[1][i] where json[1][i] == the title of the page. After BlueCodeA pointed out the spaces thing i went back and looked and realized the json they give you provides the proper links anyway… so i changed the link to json[3][i] which is the proper link and now all is well! Thanks again BlueCodeA!

1 Like

Awesome… I’ve received a lot of help along the way, so it’s nice to give back for a change… :smiley: