Note that there are some explanatory texts on larger screens.

plurals
  1. POI've created an "onclick" event handler, now how do I create an event handler for "Enter" key?
    primarykey
    data
    text
    <p>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 &amp; 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 &amp; loaded everytime the webpage is opened, but to "no" avail. Any help would be highly appreciated, thanks in advance!</p> <p>Here's the code:</p> <pre><code>&lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;link rel="stylesheet" href="playlist.css"&gt; &lt;title&gt;RTH&lt;/title&gt; &lt;meta charset="utf-8"&gt; &lt;script&gt; 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); } &lt;/script&gt; &lt;body&gt; &lt;Input type = "text" Id = "songTextInput" size = "40" placeholder = "Insert track here..."/&gt; &lt;Input type = "button" id = "addButton" onclick ="handleButtonClick();" value = "Add Song"/&gt; &lt;strong&gt; &lt;ul id="playlist"&gt; &lt;/ul&gt; &lt;/strong&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload