Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 80212

Redirecting to Information Page for specific User in Node.js

$
0
0

I have a table in which users are listed and I want the user information to open when a user (so a row in my table) is clicked on. To do this, you have to read from the table which user was clicked on and then load his data in the detail view of the user.

What I already have:

users.js:

//Userinformation 
router.get('/Information', (req, res) => {

    //here it is
    var user = req.user;

    open_selected();
    function open_selected() {
        var table = document.getElementById('tabelle');
        var cells = table.getElementsByTagName('td');

        for (var i = 0; i < cells.length; i++) {
            // Take each cell
            var cell = cells[i];
            // do something on onclick event for cell
            cell.onclick = function () {
                // Get the row id where the cell exists
                var rowId = this.parentNode.rowIndex;

                var rowSelected = table.getElementsByTagName('tr')[rowId];

                var info = rowSelected.cells[0].innerHTML;

                //you probably also want to pass this to your view
                res.render('Information', { info, user:user });

            }
        }

    }
});

My Frontend with the table: Users.ejs

<table id="tabelle" class="table table-striped cell-border table-hover" cellspacing="0" style="text-align: center">
                    <thead>
                    <tr>
                        <th style="text-align: center">UserID</th>
                        <th style="text-align: center">Rolle</th>
                        <th> </th>
                    </tr>
                    </thead>
                    <tbody>
                    <%for (var i = 0; i < users.length; i++) { %>
                    <tr>
                    <td><%=users[i].username%></td>
                    <td><%=users[i].admin%></td>
                        <td><button id="buttonAnzeigen" type="submit" name="username" data-toggle="tooltip" title="Anzeigen"><a href="/users/information"><i class="fas fa-search"></i></a></button></td>
                    </tr>
                    <!-- hallo -->
                    <%}%>
                    </tbody>
                </table>

And my Frontend, which should show the User specific Information: Information.ejs

<h1> Benutzerinformation</h1>
            <table id="tabelle" class="cell-border"  class="table table-striped" cellspacing="0">
                <thead>
                <tr>
                    <th></th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>User ID</td>
                    <td><%=user.username%></td>
                </tr>
                <tr>
                    <td>Division</td>
                    <td><%=user.division%></td>
                </tr>
                <!-- dann muss das auch bei neueNutzer die Torfreigabe!! -->
                <tr>
                    <td>Torfreigabe</td>
                    <td><%=user.gate%></td>
                </tr>
                <tr>
                    <td>Sprache</td>
                    <td><p><select id="pickingland" style="font-size: large; width: 100px; text-align:center;">
                                <option>DE</option>
                                <option>EN</option> </select></p> </td>
                </tr>
                <tr>
                    <td>Telefon</td>
                    <td><%=user.telefon%></td>
                </tr>
                <tr>
                    <td>E-Mail</td>
                    <td><%=user.email%></td>
                </tr>
                </tbody>
            </table>

I think my function in users.js is very bad and maybe that has to be placed in Users.ejs.. I just don't know how to solve it and I am happy for every help that I can get.

Tank you!


Viewing all articles
Browse latest Browse all 80212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>