Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
I can t get the following code to show anything after inputting and clicking the button that appears.I can t find a reason why. Any help?
Here is part one of the code. It sets up the website and asks for Javascript to enact.
<!DOOCTYPE HTML>
<HTML lang="en">
<HEAD>
<TITLE>Webville Tunes</TITLE>
<meta charset = "utf-8">
<script src="playlist.js"></script>
<link rel="stylesheet" type="text/css" href="playlist.css">
</HEAD>
<BODY>
<form>
<input type="text" id="songTextInput" size="40" placeholder="Song name">
<input type="button" id="addButton" value="Add Song">
</form>
<ul id="playlist">
</ul>
</BODY>
</HTML>
Here is the JavaScript on a second page:
window.onload = init;
function init() {
var button = document.getElementById("addButton");
button.onclick = handleButtonClick;
}
function handleButtonClick() (
var textInput = documentgetElementByID("songTextInput");
var songName = textInput.value;
var node = document.createElement("LI");
var textnode = document.createTextNode("Blue Suede Shoes");
node.appendChild(textnode);
document.getElementByID("playlist").appendChild(node);
li.innerHTML = songName;
var ul = document.getElementById("playlist");
ul.appendChild(li);
}
Any help would be great!
2 Answers
- 4 years agoFavorite Answer
The JavaScript code has typos.
For example, documentgetElementByID("songTextInput") should be document.getElementById("songTextInput"). It's missing the period after "document" and the "d" in "Id" shouldn't be capitalized.
You also have the line "function handleButtonClick() (" which should end with a curly brace { not a (.
Also, the last 3 lines seem unneccessary and could be messing up your page.
Try this:
window.onload = init;
function init() {
var button = document.getElementById("addButton");
button.onclick = handleButtonClick;
}
function handleButtonClick() {
// Put this in one line, I'm only using 2 lines because otherwise Yahoo cuts off the end
var textInput = document.getElementById
("songTextInput");
var songName = textInput.value;
var node = document.createElement("li");
var textnode = document.createTextNode(songName);
node.appendChild(textnode);
// Put this in one line also
document.getElementById("playlist").
appendChild(node);
}
- JohnLv 74 years ago
try this...
<input type="text" id="song" size="40" placeholder="Song name" />
<button type="button" onclick="addSong()">Add Song</button>
<script type="text/javascript">
function addSong() {
var name = document.getElementById("song");
var li = document.createElement("li");
var node = document.createTextNode(name.value);
li.appendChild(node);
var list = document.getElementById("playlist");
list.appendChild(li);
name.value = "";
}
</script>