Choosing and transferring the table data to be shown in the pop-up box

Having encountered an issue with a popup trigger placed inside a td element, I am seeking advice on how to pass table data into the popup window. Unfortunately, the main popup window was positioned outside the while loop, resulting in multiple instances of the popup window appearing instead of just one. How can I efficiently transfer the table results to the popup without facing this replication problem?

   $result = mysqli_query($conn, $sql);
   while ($row = mysqli_fetch_assoc($result)) {
    // Loop through the table results and perform necessary actions
  ?>
      <td>
          <a href="#0" id="info" class="info popup-trigger" 
      title="info">View</a>
      </td>
      <td style="font-size:16px;"><STRONG><?php echo $row['eqdesc']; 
       $eqid=$row['eq_inv_id'];?> 
      </STRONG></td>
      <td><?php echo $row['eq_inv_id']; ?></td>
      <td style="color:red; font-size:15px;"><strong><a href="timeline.php? 
        emp_no=<?php echo 
       $row['empl_no'];?>" style="color:inherit;"><?php echo 
       $row['empl_firstname']; ?></a></strong> 
       </td>
      <td style="color:red; font-size:15px;"><strong><a href="timeline.php? 
       emp_no=<?php echo 
       $row['empl_no'];?>" style="color:inherit;"><?php echo 
        $row['middlename']; ?></a></strong> 
        </td>
      <td style="color:red; font-size:15px;"><strong><a href="timeline.php? 
      emp_no=<?php echo 
          $row['empl_no'];?>" style="color:inherit;"><?php echo 
      $row['empl_lastname']; ?></a> 
      </strong></td>
      <td><?php echo $row['brand']; ?></td>
        <td><?php echo $row['serial_no']; ?></td>
        <td><?php echo $row['eq_state']; ?></td>
        <td><?php echo $row['eq_condition']; ?></td>
      <td><?php echo $row['curr_equip_loc']; ?></td>
      </tbody>
        <?php
        }
        ?>
      </table>
      </div>
      <div id="#0" class="popup" role="alert">
      <div class="popup-container">
      <a href="#0" class="popup-close img-replace">Close</a>
      <h2 class="modal-heading">EQUIPMENT INFORMATION</h2>
      <label>EMPL. NO.:<strong><?php echo $row['eq_inv_id'];?></strong> 
      </label><br>
      <label>FIRST NAME:</label><br>
      <label>MIDDLE NAME:</label><br>
      <label>LAST NAME:</label><br>
      <label>EQ DESCRIPTION:</label><br>
      <label>DESCRIPTION:</label><br>
      <label>BRAND:</label><br>
      <label>TAG NO.:</label><br>
      <label>SERIAL NO.:</label><br>
      <label>MODEL NO:</label><br>
      <label>IP ADDRESS:</label><br>
      <label>DATE ISSUED:</label><br>
      <label>EQ STATE:</label><br>
      <label>EQ CONDITION:</label><br>
      <label>DATE PURCHASED:</label><br>
      <label>AGE:</label><br><BR>
      <label>PRICE:</label><br>
      <label>LOCATION:</label><br>
      <label>REMARKS:</label><br>
      <label>PAR NO.:</label><br><BR>
      <button class="">UPDATE</button>
      <button class="">Assign this equipment to an employee</button>
      <button class="">EQ HISTORY</button>
      </div>
      </div>

      <script>
      jQuery(document).ready(function($){
      //open popup
        $('.popup-trigger').on('click', function(event){
       event.preventDefault();
        $('.popup').addClass('is-visible');
        });

       //close popup
       $('.popup').on('click', function(event){
      if( $(event.target).is('.popup-close') || $(event.target).is('.popup') 
      ) {
       event.preventDefault();
      $(this).removeClass('is-visible');
      }
      });
      //close popup when clicking the esc keyboard button
      $(document).keyup(function(event){
    if(event.which=='27'){
    $('.popup').removeClass('is-visible');
     }
    });
    });
    </script>

https://i.sstatic.net/yvNTJ.png https://i.sstatic.net/aepjb.png

Answer №1

UPDATED

I have finally cracked the code! By separating the display of modal and passing the table result, I managed to utilize Bootstrap for modal display. The script below focuses solely on passing the table result into the pop-up modal. Here is the functional code.

    $result = mysqli_query($conn, $sql);
    while($row = mysqli_fetch_assoc($result)) {
     ?>

      <td>
        <!-- Button trigger modal -->
       <button type="button" value="<?php echo $row['eq_inv_id'];?>" 
        onclick="foggyDetails(this)"  class="btn btn-primary" data- 
        toggle="modal" data-target="#exampleModalCenter">
      View EQ
       </button>
      </td>
      <td><?php echo $row['eq_inv_id']; ?></td>
      <td style="font-size:16px;"><STRONG><?php echo $row['eqdesc'];?> 
       </STRONG></td>
      <td style="color:red; font-size:15px;"><strong><a 
      href="timeline.php?emp_no=<?php echo $row['empl_no'];?>" 
       style="color:inherit;"><?php echo $row['empl_firstname']; ?></a> 
       </strong></td>
      <td style="color:red; font-size:15px;"><strong><a 
      href="timeline.php?emp_no=<?php echo $row['empl_no'];?>" 
       style="color:inherit;"><?php echo $row['middlename']; ?></a> 
        </strong></td>
      <td style="color:red; font-size:15px;"><strong><a 
       href="timeline.php?emp_no=<?php echo $row['empl_no'];?>" 
       style="color:inherit;"><?php echo $row['empl_lastname']; ?></a> 
       </strong></td>
      <td><?php echo $row['brand']; ?></td>
        <td><?php echo $row['serial_no']; ?></td>
        <td><?php echo $row['eq_state']; ?></td>
        <td><?php echo $row['eq_condition']; ?></td>
      <td><?php echo $row['curr_equip_loc']; ?></td>
     </tbody>
     <?php
      }
     ?>
       </table>
       </div>
       <!-- Modal -->
       <div class="modal fade" id="exampleModalCenter" tabindex="-1" 
       role="dialog" aria-labelledby="exampleModalCenterTitle" aria- 
      hidden="true">
      <div class="modal-dialog modal-dialog-centered" role="document">
       <div class="modal-content">
       <div class="modal-header">
    <h5 class="modal-title" id="exampleModalLongTitle">EQ Information</h5>
    <button type="button" class="close" data-dismiss="modal" aria- 
      label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
  <label>Equipment ID:<strong><span id="foggy"></span></strong><br>
  <label>Description:<strong><span id="foggy2"></span></strong><br>
  <label>Brand:<strong><span id="foggy3"></span></strong>
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data- 
     dismiss="modal">Close</button>
    <button type="button" class="btn btn-primary">Save changes</button>
     </div>
      </div>
      </div>
      </div>

Script

     function foggyDetails(details){
        var invId = details.value;

       $.ajax({
           url: "test.php",
           method: "GET",
           data: {"invId": invId},
           success: function(response) {

             // Parsing the JSON string to javascript object
             var reu = JSON.parse(response);

             //Displaying in proper field
             $("#foggy").text(reu.eq_inv_id);
             $("#foggy2").text(reu.eqdesc);
             $("#foggy3").text(reu.brand);
           }
         });
       }

test.php

        <?php
        include('connect.php');

        $invId=$_GET['invId'];
        $sql="SELECT * FROM eq_inv WHERE eq_inv_id='$invId'";
        $result=mysqli_query($conn, $sql);

        $a=mysqli_fetch_object($result);
        echo json_encode($a);    //returning the json string
         ?>

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

To update the JSON values in a YAML file using Python, you can embed the JSON within the YAML

I have a YAML configuration file that looks like this: api: v1 hostname: abc metadata: name: test annotations: { "ip" : "1.1.1.1", "login" : "fad-login", "vip" : "1.1.1.1", &qu ...

Dynamic element not firing jQuery event

My question is... // Using ajax to dynamically create a table $(".n").click(function(){ var id= $(this).closest('tr').find('td.ide2').html(); //for displaying the table $.ajax({ type: 'POST&ap ...

Is it the practice of the Signalr server to dispatch a consolidated response for all pending requests when polled using longpolling?

We have been receiving a series of pending requests for a signalr client, which are grouped together as an array in the response of a poll. Here's how it looks: {"C":"s-0,9E632", "M":[ 84 {"H":"MyHub","M":"SetSomething","A":[{"myProp1":"setting","myP ...

What impact does reducing the window size have on my header?

While working on a website with a navigation bar, I encountered an issue where the navbar was not responsive. When the window size was reduced, the nav bar shifted to an awkward position vertically, as shown in the first image. The navbar shifts below the ...

The centrally-aligned flexbox div remains at a fixed size, preventing any text truncation within its nested elements

My goal is to truncate the lengthy text in the span with the id of first-item when the screen size decreases. However, I am encountering an issue where setting margins on the parent element prevents it from shrinking, thus causing the truncation not to wor ...

Building an Ajax request for Redux-Form operation to communicate with Mongo in a structured manner

I'm relatively new to working with JavaScript and React, and I've been using Redux-Form to add items to my MongoDB. The form is set up correctly and the API connection to the database is defined, but I'm struggling with structuring the actio ...

I have created a Joomla Template that incorporates my own CSS through JavaScript. Is there a method to include a distinct version tag to my custom CSS file, such as custom.css?20180101?

My usual method involves adding a unique tag to the css path in the html section, but my template is incorporating custom CSS through Javascript: if (is_file(T3_TEMPLATE_PATH . '/css/custom.css')) { $this->addStyleSheet(T3_TEMPLATE_URL . &apo ...

Customizing CSS in Angular Components: Taking Control of Style Overrides

I am new to working with Angular and HTML. Currently, I have two different components named componentA and componentB, each having their own .html, .css, and .ts files. In the componentA.css file, I have defined some styles like: .compA-style { font- ...

Styling Images with Gradient using CSS

Looking to create a unique effect on an image by adding a radial gradient that seamlessly fades into the background color. Despite my efforts, I haven't been able to achieve this using filters and my current code is a bit messy. Here's what I ha ...

Tutorial on integrating jquery ui's '.droppable' feature with the jQuery '.on' method

I have a main div with three inner divs labeled 1, 2, and 3 as shown below: <div id="main"> <div style="height:30px; background-color:yellow;" class="bnr">Banner</div> <div style="height:30px; background-color:yellow;" class=" ...

Using CSS to automatically convert a table into one column layout with labels from the thead section

Is it possible to automatically create the labels for data when converting a multi-columns table into one column using CSS and taking the information from the thead section? This resource discusses how to convert a multi-column table into a single column ...

Utilizing REST API to showcase MySQL database information in an HTML table

I am working on a project where I need to fetch data from a MySQL database and display it in an HTML table. To achieve this, I have created a REST API using JavaScript. However, when I try to retrieve the data and display it in table rows, I encounter an ...

Error occurred during SCSS rendering process: [Internal Error: Unable to locate or read the specified file.]

When trying to create a website using scss, I encounter an error every time I save the scss file. Strangely, after saving it multiple times, the file will render properly. Although this issue is minor, it really bothers me. I have searched for a solution ...

Issue with Left Alignment of Tabs in Material-UI

As of now, material-ui's latest version does not provide support for aligning tabs to the left in the component. However, I came across a workaround on this GitHub page I have implemented the same workaround, and you can view it here: Unfortunately, ...

Bootstrap 4 and Angular 7 application experiencing issues with toggle button functionality in the navigation bar

I am currently working with Angular7 and Bootstrap4. I am attempting to integrate a navbar into my application, but I am facing an issue where the toggle button does not work when the navbar is collapsed. It is important for me to mention that I do not wa ...

Creating a polygon path in Google Maps v3 using an array of coordinates

I'm currently working on creating a polygon around US counties. The coordinates for this polygon are coming from a database and then being json encoded for use in JavaScript. Below is the JSON encoded array generated from PHP code: {"Abbeville-sc":[[ ...

What is the best way to arrange <div> elements with text inside without moving the text?

I need help figuring out how to stack one or more <div> elements on top of another <div> element while maintaining the text content within each. My issue is illustrated in this fiddle: https://jsfiddle.net/rd268ucy/1/. When attempting to drag o ...

Tips for styling an inline list using CSS before revealing it with jQuery's .show method:

In my project, I want to display a row of 'cells' which are simply images of black or white squares based on their ID. The issue I am facing is that when the button is clicked, the row list is shown without the CSS applied, and then after a brief ...

Radio boxes vanish in Safari when -webkit-perspective is applied

Check out this quick demonstration on Safari only: http://jsfiddle.net/2late2die/8AJnD/ If you remove the perspective style, all checkboxes will appear normal. When using -webkit-transform-style:preserve-3d, the checkboxes disappear. This issue seems to af ...

How to target the DIV elements that have at least one unordered list (UL) inside using CSS selector or JavaScript

Imagine a hierarchy structured like this: <div class="first_level"> <div class="second_level_1"> <div class="third_level_1"> <div class="fourth_level_1"> <ul><li></li><li></li></ ...