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

stringify data in an array with local storage

$
0
0

I have tried several times to get this to work, i am making a leaderboard with a text function input that sets the local storage values. I can not get it to work with making my key an array ,so that i can have multiple values to the same key.

var userAvg = document.getElementById('avg');
var userAmount = document.getElementById('amount');


function addData() {
  localStorage.setItem('userName',userName.value);
  localStorage.setItem('userAvg', userAvg.value);
  localStorage.setItem('userAmount', userAmount.value);
  var table = document.getElementById("myTable");
  var row = table.insertRow(4);
  var cell1 = row.insertCell(0);
  var cell2 = row.insertCell(1);
  var cell3 = row.insertCell(2);
  cell1.innerHTML = navn.value;
  cell2.innerHTML = avg.value;
  cell3.innerHTML = amount.value;
}

<html></div>
<div id="board">
<ul id="list"></ul>
  <br/>
  Navn <input type="text" id = "navn" />
  <br/>
  Gennemsnitlig Promille <input type="text" id = "avg" />
  <br/>
  Antal genstande i alt <input type="text" id = "amount" />
  <br/>
  <br/>
  <button type="button" onclick="addData()">Tilføj Data </button>
  <table id="myTable">
      <tr>
          <th onclick="sortTable(0)">Navn</th>
          <th onclick="sortTable(1)">Gennemsnitlig Promille</th>
          <th onclick="sortTable(2)">Antal Genstande i alt</th>
      </tr>
<html>

Viewing all articles
Browse latest Browse all 67527

Trending Articles



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