Having trouble implementing button functionality in a web app using JS, jQuery, HTML, and CSS along with an API integration

I am currently developing a web search engine that utilizes the Giphy API... However, I've encountered difficulties with the button function. I have created buttons to modify the page format and adjust the number of search results displayed.... The Web interface functions properly, but the buttons refuse to work. I've attempted using inline code and linking external files without success. This project is due on Monday, and I've been dedicating all week to it... Please assist! I'm at a loss here...

Here's an excerpt of the code...

enter code here

 /* JavaScript Code Snippet */
function () {
    function giphySearchEngine(keyword, limit) {
      return fetch(`http://api.giphy.com/v1/gifs/search?q=${keyword}&api_key=h5nEbFf0nz3FmKUhFMFajDQpM6ew66XF&limit=${limit}`)
        .then(response => response.json());
    }
  
   // Remaining JavaScript functions...
   
}
/* CSS Stylesheet */

/* Font */
body{
font-family:
'Bangers', cursive;
color:#393e46;
}
  /* color layout */
.background{
    color:#f7f7f7;
}

  /* Responsive Layout */
@media screen and (max-width: 800px) {
    .col {
      flex: 50%;
      max-width: 50%;
    }
  }

/* Additional CSS styles ... */ 
<!DOCTYPE html>
<!-- HTML Structure -->

<!-- Head Section -->
<!-- Meta tags
    Bootstrap CSS 
--> 

<!-- Theme-related links -->

<!-- Opening Body Tag -->
<!-- Header Section -->
<h1>Giphy Image Changer</h1>

<!-- Form for Search Input -->
<form id="searchForm">

<!-- Buttons to change the view -->
<button class="btn" onclick="one()">1</button>
<button class="btn" onclick="two()">2</button>
<button class="btn active" onclick="four()">4</button>

<!-- Container for displaying results -->
<div class="container">

<!-- Show section with gif results -->
<div id ="show" class="row"></div>

<!-- Button Group for Result Limit -->
<div class="btn-group mr-3 mx-md-3"  role="group" aria-label="Second group">
  <button type="button" id ='btn6'  class="btn">6</button>
  <button type="button" id ='btn12' class="btn">12</button>
  <button type="button" id ='btn18' class="btn">18</button>
</div>

  <!-- Closing Tags -->
<footer>
    <!-- Footer Section -->
</footer>

<!-- Scripts declaration -->
<script src="https://code.jquery.com/jquery-3.5.0.min.js"></script>
<script type = "text/javascript" src="js/demo.js"></script>
  
</body>
  
</html>

Answer №1

Update: Your current code snippet is missing the logic to read and display search results

     $('#btn6').on('click', async function() {
        console.log('Searching for 6 results!');
        const newResults = await giphySearchEngine(keyword, 6);
        // No action taken with the new results.

      });

You have only handled the first search promise. You must handle each search request and iterate through the results.

Consider wrapping it in a separate function

async function main(keyword) {
    async function search(keyword) {
      const result = await giphySearchEngine(keyword);
      $('#show').html('');    

      let promises = [];
      result.data.forEach(gif => {
         let img = new Image();
         img.src = gif.images.original.url;
         promises.push(resultLoad(img));
        images (img);
      });
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sorting by price using the ng-repeat directive is not suitable for this

Utilizing angular's ng-repeat along with orderBy on a product catalog page to sort the products based on a select change. The ordering by name using orderBy works as expected, however, when it comes to price it sorts like this: 1,10,11,12,13,14,2,3,4 ...

Utilizing the "row" and "column" attributes in Angular (Flexbox) results in significant spacing between input fields within the HTML code

I'm working on aligning 2 input fields side by side within the same line. To achieve this, I've been utilizing Flexbox. However, I've observed that when using Flex with both 'row' and 'column', it introduces extra spacing ...

How does adding padding cause two horizontal divs to become vertical?

I noticed that when I remove the padding from the code below, two vertical divs become horizontal. This is confusing to me because I thought padding only affects internal spacing. I was expecting the two divs to be aligned horizontally. <style> #w ...

Formatting Dates in Node.js

Can someone assist me in understanding how to properly format the print date shown below? Thu Sep 06 2018 18:18:26 GMT+0530 I attempted to use console.log(new Date()) However, the output generated was 2018-09-06T12:48:25.776Z I am unsure of how to co ...

Managing extensive geographical information through HTTP

What is the most efficient way to transmit a substantial volume of map information via HTTP for rendering on the client side? There must be a more effective approach than simply transmitting a JSON file containing all map data. I am interested in how maj ...

Having trouble getting Video.js SWF to work on Internet Explorer?

I've been working with video.js and am having trouble getting it to function properly on Internet Explorer. I have added the swf file like this: videojs.options.flash.swf = "http://vjs.zencdn.net/4.2/video-js.swf " Here is the code for the video pla ...

Using dynamic forms with HABTM relationships

The application I'm developing involves Reports, Sections, and Writers. A Report has multiple Sections and Writers. Sections and Writers have a many-to-many relationship because a writer can write several sections, and a section can be written by mul ...

Displaying the identical date on two separate Ajax Calendar Extender controls in Asp.net

I am facing an issue with some ajax calendar extenders. I have two similar calendars and two textboxes, each linked to one calendar. <asp:TextBox ID="txt1" runat="server"</asp:TextBox> <cc1:CalendarE ...

The issue with anchor links not functioning correctly in Chrome's desktop browser has been identified

I am interested in utilizing the greenfair CSS template available at this link. However, I have encountered an issue where the anchor links in the navbar do not work properly in Chrome (they function correctly in Firefox and IE). How can I resolve this pro ...

instructions on sending the complete product quantity to the payment gateway

I am currently in the process of developing an ecommerce website using Django. When a user clicks on checkout, an HTML billing form appears prompting them to enter their address and email information. Previously, I successfully passed data such as email t ...

Implement a default dropdown menu that displays the current month using Angular and TypeScript

I am looking to implement a dropdown that initially displays the current month. Here is the code snippet I have used: <p-dropdown [options]="months" [filter]="false" filterBy="nombre" [showClear] ...

Updating hyperlinks from dynamic php links to stable static links

I have a script that predominantly uses absolute addressing, but now I need to switch to relative addressing. The problem I'm encountering is when trying to change the links in PHP from: <link href="<?php print $theme; ?>style.css" type="tex ...

Having trouble updating the icon on my website using FontAwsome

Just a heads up - I'm not familiar with HTML/CSS/JS. This template is pre-made, and I'm simply making some adjustments to it. Hello, I'm currently working on my portfolio website and I want to display my projects based on the programming la ...

Arrange the object's key-value pairs in ng-repeat by their values

I'm completely new to AngularJS and I am working with an API that returns key-value pairs related to different sports. $scope.sports = { 1: "Soccer", 2: "Tennis", 3: "Basketball" ... }; My challenge is sorting these items by sport name: <ul> ...

Ways to eliminate HTML tags from the output while preserving the formatting

I recently encountered an issue working with a MySQL database. To prevent SQL injections, I utilized: $entities_correction = htmlspecialchars($Query, ENT_COMPAT, 'UTF-8'); However, when attempting to display the data to the user, it appeared as ...

Use the Vue `this.$router.push` method inside a setTimeout function

I have a landing page '/' that users will see first when they visit our website. I want to display a loading wheel for 5 seconds before automatically redirecting them to the login page '/login'. My Landing.vue page in Vue and Bulma.io ...

Avoid repetitive comment form submissions

I have a comment form for my article and I want to prevent re-submission. Wordpress handles this well without causing the browser to request a form re-submission. However, I can't figure out how they do it even though our methods are similar. My Appr ...

Placing a box in the center of its parent container using CSS positioning

Check out this code snippet : HTML <div class="app-cont"> <div class="app-head"> Additional Comments : </div> <div class="app-main"> balallalalalallalalalala <br/> jaslnflkasnlsnlk ...

Two nested divs positioned below text within a parent div

I am styling a content div with text and two child divs positioned next to each other within the content div. My goal is to have the child divs display below the text, rather than beside it. body { text-align: center; } #first, #second { border: so ...

Using an arbitrary object as an argument in a CoffeeScript anonymous function

When I execute the below Coffeescript code: @total = (a, b) -> a + b The resulting compiled Javascript is: (function() { this.total = function(a, b) { return a + b; }; }).call(this); Is there a method in Coffeescript to substitute ...