Using fetch in an event listener?

This fetch() api request seems to work fine, until I try and put it in a click listener, then it returns an error. Please enlighten me :slight_smile:

I think I’ve actually just figured it out…

<input id="searchTerm" type="text" placeholder="search for character" name="searchTerm">
      <button id="search-button" type="submit">Search</button>

I had this input wrapped in a form and that was preventing the value of #searchTerm from getting sent to the variable appended to the api URL. I swear I tried to solve this problem for a long while before posting a question. As soon as I did, finally found a post with similar problem/solution.

1 Like