I took this simple code from Ch 3 of OREILLY's "Head First HTML5 Programming". I made a "few" adjustments, but nothing major. As you see, it's merely a simple little playlist manager with a few functions & alerts. The webpage appears just as it should. Click on the "Add Song" button, it adds song to playlist. Everything works as it should, EXCEPT if you hit "Enter" on your keyboard, all the songs in the playlist simply disappear. How do I create an event handler for the "Enter" key? All I know is that the "Enter" keycode is 13, how exactly do I apply this to my page? "ALSO", as you can see, I attempted to make it so that any song added to the playlist would be saved in Local Storage & loaded everytime the webpage is opened, but to "no" avail. Any help would be highly appreciated, thanks in advance!
Here's the code:
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="playlist.css">
<title>RTH</title>
<meta charset="utf-8">
<script>
loadPlaylist();
function handleButtonClick() {
var textInput = document.getElementById("songTextInput");
var songName = textInput.value;
if (songName == "") {
alert("Enter a track!");
} else {
alert("Congrats...track is now being added!");
}
var li = document.createElement("li");
li.innerHTML = songName;
var ul = document.getElementById("playlist");
ul.appendChild(li);
save(songName);
}
</script>
<body>
<Input type = "text" Id = "songTextInput" size = "40" placeholder = "Insert track here..."/>
<Input type = "button" id = "addButton" onclick ="handleButtonClick();" value = "Add Song"/>
<strong>
<ul id="playlist">
</ul>
</strong>
</body>
</html>