ul
list:
JS:
function init() {
var botao = document.getElementById("addButton");
botao.onclick = handleButtonClick;
}
function handleButtonClick() {
var textInput = document.getElementById("songTextInput");
var songName = textInput.value;
if (songName == "") {
alert("Por favor, adicione um pergunta");
} else {
//alert("Adicionando a música " + SongName);
var li = document.createElement("li");
li.innerHTML = songName;
var ul = document.getElementById("playlist");
ul.appendChild(li);
}
}
HTML:
<form>
<input type="text" id="songTextInput" size="40" placeholder="Nome da música">
<input type="button" id="addButton" value="Adicionar música">
</form>
<ul id="playlist">
</ul>
The problem is: When I define my input with type=button
, this javascript works, but when I set it to type=submit
, it runs legal until the first condition or with the second alert condition, but does not add the string in the list.
Does anyone know why this happens?