<form>
<input name="Team1" id="team1" type="text" value="Team1?">
<button id="dostuff" value="Go">Go</button>
</form>
<div id ="nicteamcolumn">Team: </div>
<script>
$('#dostuff').click(function(e) {
var team1 = $('input[name="Team1"]').val();
if (typeof(Storage) !== "undefined") {
if (localStorage.teamlist) {
localStorage.teamlist= localStorage.teamlist + team1;
}
else {
localStorage.teamlist = " ";
}
$('#nicteamcolumn').html("Team:" + "<br>" + localStorage.teamlist + "<br>")
}
}
</script>
Basically, when the button is clicked, I am taking the input from Team1, add it to localStorage.teamlist
, and changing the html of #nicteamcolumn
to localStorage.teamlist
I am getting a weird output the first time I click the button. It prints the value for team 1 a ton of times over and over. The 2nd click and on seem to be working fine as well as when I close the page and coming back and keep adding to the list.
Any help would be greatly appreciated?