lundi 24 avril 2017

If statement not working properly // javascript

How come 'field has been left empty' never appears when nothing has been entered into the input field. When nothing has been entered I want 'field has been left empty' to appear and 'word list' to disappear. How can I do this?

function start() {
  var word = "Word List";
  Value = document.getElementById('input1').value;
  var i = Value.length

  if (word.trim() === "") {
  word = "field has been left empty"

}
  document.getElementById('errormessage').innerHTML = word
  while (i--) {



  document.getElementById('message').innerHTML = Value[i] + "<br/>" + document.getElementById('message').innerHTML;


}
}
<!DOCTYPE html>
<body>
<span>enter word: </span>
<input type="text" name="name" id=input1></input>
<button onclick="start()" class="button" type = "button">enter</button><br><br>
<p id="errormessage"></p>
<p id="message"></p>
</body>

Aucun commentaire:

Enregistrer un commentaire