1

I am trying to add users to the list using javascript, I dont know why my code is not working.

Here is my code.

HMTL

<form id="myform">
    <h2>Add a User:</h2>
    <input id="username" type="text" name="username" placeholder="name">
    <input id="email" type="email" name="email" placeholder="email">
    <button onclick='addUser()' type="submit">add user</button>
</form>

<h2>UsersList:</h2>
<ul id="users"></ul>

JavaScript

<script>
    var list = document.getElementById('users');
    function addUser(){
        var username =document.getElementById('username').value;
        var email = document.getElementById('email').value;
        var entry = document.createElement('li');
        entry.appendChild(document.createTextNode(username + '' + email));
        list.appendChild(entry);
    }
</script>
zaf
  • 22,776
  • 12
  • 65
  • 95
user3282116
  • 39
  • 1
  • 8
  • possible duplicate of [jQuery: how to add
  • in an existing
      ?](http://stackoverflow.com/questions/1145208/jquery-how-to-add-li-in-an-existing-ul)
  • – zaf Apr 03 '14 at 04:53
  • Im trying to implement in pure js – user3282116 Apr 03 '14 at 04:55
  • @user3282116 In that case, I will remove the query tag for you. – zaf Apr 03 '14 at 05:34
  • And also http://stackoverflow.com/questions/17773938/add-a-list-item-through-javascript – zaf Apr 03 '14 at 05:35