Determine the specific table entry that was clicked on

Currently, I am working on developing a dynamic table that includes a button in one of its columns, which triggers a bootstrap modal. I'm a bit unsure on how to determine which button was clicked and how to populate the table accordingly. Admittedly, my experience with markups is limited. Here is what I have managed to put together:

div.span12
table.table.table-hover
    thead
        tr
            th Patient Name
            th Phone Number
            th History
    tbody
        each pat in patients
            tr
                td #{pat.name}
                td #{pat.phone}
                if (0<pat.history.length)
                    td #{pat.history[0]}
                else
                    td No history

a.btn(data-toggle="modal", href="#myModal") Launch
div.modal.hide(id="myModal")
    .modal-header
        button(type="button", class="close", data-dismiss="modal") x
        h3 Modal Header
    .modal-body
        p One fine body...
    .modal-footer

My goal is to replace the td #{pat.history[0]} section with a unique identifier that, when clicked, will trigger the modal popup and display the corresponding patient data. Any advice on how I can achieve this?

Answer №1

I have come across a solution, but I must admit it feels a bit messy to me. If there is a cleaner alternative, I would appreciate any suggestions:

            each pat,key in patients
            tr
                td #{pat.name}
                td #{pat.phone}
                if (0<pat.history.length)
                    td 
                        span(onclick='console.log(#{key})') #{pat.history[0]}
                else
                    td No history

Using this approach, I am able to link each element from my patients array to the corresponding row that was clicked, allowing me to display the desired content in a modal. However, I am unsure if this is the most appropriate method to achieve this. Any feedback would be greatly appreciated!

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

Distinguishing CSS Variances on ASP.Net Site with Android 4+

I am encountering an issue with my current ASP.Net Mobile Website design. It is rendering correctly on android phones pre 4, iPhones, and Blackberries. This problem requires a bit of setup to explain... CSS tr { color: #00ff00; } #MasterBackButton { ...

Converting numbers in React Native, leaving only the last four digits untouched

When mapping biomatricData.ninId, the value I am receiving is "43445567665". biomatricData.ninId = 43445567665 My task now is to display only the last 4 digits and replace the rest with "*". I need to format 43445567665 as follows: Like - *******7665 ...

Axios is causing my Pokemon state elements to render in a jumbled order

Forgive me if this sounds like a silly question - I am currently working on a small Pokedex application using React and TypeScript. I'm facing an issue where after the initial page load, some items appear out of order after a few refreshes. This make ...

Tips for altering the class of an HTML button dynamically when it's clicked during runtime

I currently have a set of buttons in my HTML page: <button id="button1" onclick="myFunction()" class="buttonClassA"></button> <button id="button2" onclick="myFunction()" class="buttonClassA"></button> <button id="button3" onclic ...

the attempt to send an array of data to the $.ajax function was unsuccessful

let myArray = []; myArray.push(someValue); let requestData = { action: myAction, array: myArray }; $.ajax({ type: "POST", data: requestData, url: requestUrl, success: handleSuccess, error: handleError }); When ...

Plugin for turning text into "leet speak" using jQuery and Javascript

Recently, I've been on the hunt for a 1337 translator that I can seamlessly integrate into a jQuery plugin. While I believe I'm making progress, I can't shake off the feeling that something's amiss. My gut tells me that what I currently ...

Experiencing a bug in my express application: TypeError - Unable to access properties of undefined (reading 'prototype')

I've encountered the TypeError: Cannot read properties of undefined (reading 'prototype') error in my javascript file. Despite researching online, it seems that many attribute this issue to importing {response} from express, but I am not doi ...

Implementing pagination within nested ng-repeat in Angular app

I am currently utilizing Angular along with the Material library in my project. I am facing an issue with two nested ng-repeat loops within md-tables. The problem lies in the fact that the variable is getting overridden with each request in the nested loop ...

Displaying data stored in a database using JSON format with Ember

I seem to be facing a challenge once again. Let me elaborate on what I am trying to achieve. Within the teammembers template, I aim to display information about Team Members and their details from a specific team by joining 3 tables. Here is an example o ...

The debate between utilizing CDN or installing a library through NPM

My journey with NPM has just begun, and I am struggling to grasp how the files within node_modules get integrated into my index.html. Scenario 1: CDN Take jQuery, for instance. When using a CDN, it's as simple as adding the CDN link to a <script& ...

Exploring the Benefits of Using AJAX with Single or Multiple JavaScript Files

Here's a question for best practices. I'm working on building an AJAX application where the main page loads everything through AJAX into the content section. Should I merge all my javascript files into one that is loaded on the main page, or spli ...

Issues with tab functionality in Bootstrap 4.0.0

Using the bootstrap tabs control, it appears correctly in bootstrap 3.3.7 https://jsfiddle.net/steve_richter/evn2ncbo/7/ <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"& ...

When working with an Angular application, IE9 may display the error message: "An internal error occurred in the Microsoft Internet extensions"

My application is encountering an issue in IE9: Error: A Microsoft Internet Extensions internal error has occurred. Error: Access is denied. When using IE's dev tools for debugging, the issue seems to be related to localStorage. if (localStorage) ...

Utilize the power of Bootstrap Modals to enhance your form validation with a seamless integration of Jquery

I have a few questions about JQuery syntax: 1) The modal is not showing up. Could this be related to an operator (&&) issue? How can I fix it? It should only appear if the input is valid. 2) How do I combine preventDefault with valid classes when submitt ...

"Exploring ways to implement validation for multiple email addresses in a textarea using JQuery or JavaScript, while allowing the addresses to be separated by semicol

NOTE: Each email ID must be unique. An empty string value is allowed to be added. Email IDs should be separated by semicolons and commas. Basic validation of email IDs is necessary for entry. [![ $("#d-notification").focusout(function () { var ...

Modify object rotation animation direction using keyboard controls in Three.js

Adjusting the object rotation direction with key controls is within my capability by utilizing the following code: case 37: scene.rotation.x -= 0.01; break case 38: scene.rotation.z -= 0.01 break Nevertheless, the rotation remai ...

Origin of SVG Circle Stroke

Describing my current issue is proving to be challenging, but I'll do my best: My project involves creating an SVG circle progress bar and fortunately, I came across a great example that aligns with what I aim to achieve. I prefer not to use any thir ...

Why is AngularJS $http response undefined?

My $http call in AngularJS is returning undefined when I try to access the data in my controller. What could be causing this issue? Despite using .then to handle promises, the data passed to the controller seems to become undefined. Can you help me figure ...

Scrolling to specific ID scrolls only in a downward direction

I have been using fullpage.js for my website and I am facing an issue. When I create a link and connect it to an id, everything works perfectly. However, I am unable to scroll back up once I have scrolled down. Here is the HTML code: <a href="#section ...

What is the best way to implement a function on every item within a specific class?

I'm new to coding and I have a website that showcases job listings. I want to create a function that dynamically changes the logo of a company based on the first 50 characters of the company name mentioned. The current function only works for the firs ...