1

I am trying to create a user table for my website, where the user can see their first name and last name in a table after they register and login. The user detail is stored in the HTML5 Local Storage. Is there a better way to update the table with more users, rather than creating more .

Here is my table:

<table id="rankTable">
    <tr>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Top Score</th>
    </tr>
    <tr>
        <td id="_firstName"></td>
        <td id="_lastName"></td>
        <td></td>
    </tr>
</table>

Here is the full working snippet: https://jsfiddle.net/MuddasarAshfaq/r62zmjw4/9/

Muddy
  • 382
  • 3
  • 14

1 Answers1

0

Assuming that u have stored your stored firstname and lastname as "fname" and "lname" in your localStorage

var table = document.getElementById("rankTable");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = localStorage.getItem("fname");
cell2.innerHTML = localStorage.getItem("lname");
Rajkumar Somasundaram
  • 1,225
  • 2
  • 10
  • 20