0
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <h1>Playlist</h1>
  <form>
    <input type="text" id="songInput" placeholder="Enter a song">
    <input type="button" id="songButton" value="Add to Playlist">
  </form>

  <ul id="playlist">
  </ul>
</body>
</html>

The above html is linked to the following javascript:

window.onload = init;

function init(){
  var button=document.getElementById("songButton");
  button.onclick=handleSongButtonClick;
}

function handleSongButtonClick(){
  var input = document.getElementById("songInput");
  var songName = songInput.value;
  var ul = document.getElementById("playlist");
  var li = document.createElement("li");
  li.value=songName;
  ul.appendChild(li);
}

What is the problem when i enter a song all it gives is a bullet and no text value? Please help it can be found here http://jsbin.com/EROcOGo/2/edit

2
  • 3
    You'd be surprised how little "not working" does to describe your issue. Commented Dec 20, 2013 at 17:23
  • List items don't have a value property, IIRC. Commented Dec 20, 2013 at 17:23

4 Answers 4

3

You can use innerText

function handleSongButtonClick(){
  var input = document.getElementById("songInput");
  var songName = input.value;
  var ul = document.getElementById("playlist");
  var li = document.createElement("li");
  li.innerText=songName; // Change here
  ul.appendChild(li);
}

Modified jsBin

Sign up to request clarification or add additional context in comments.

Comments

2

The .value property is typically only useful with <form>-related elements -- <input>, <textarea>, etc.

li.value = songName; // has no affect

To set the text content within other elements, you can either:

  • Set .textContent (standard) and .innerText (IE):

    li.textContent = li.innerText = songName;
    
  • Create and append a text node.

    li.appendChild(document.createTextNode(songName));
    

Comments

0

Use input.value instead of songInput.value;

li.innerText=songName; 

instead of

li.value=songName;

Comments

0

Here you have it: http://jsbin.com/UzeZasa/3/edit?html,js,output

First songInput wasn't declared (was named only input. Second: value isn't an attribute of li. You have to set the inner-html of that tag with element.innerHTML = content.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.