I'm trying to simulate a chat messaging system using pure JS (no server though, so really just uploading and displaying text) but am having trouble as I'm pretty new to JavaScript. I wrote this code but nothing happens when I click submit. Is my code having a huge error anywhere that I am not catching? If so, how can I fix it?
I am trying to use the javascript function to generate a div under the class container, with parent div chatMsg.
<div id="chatMsg" class = "chatMsg" >
<div class="container">
//some other HTML here
</div>
</div>
<div class = "sendText">
<form name = "sendMsg">
<textarea name="Message" class="msg" ></textarea>
<input type="submit" name = "submit" value="Send!" onclick = "addChatMessage()">
</form>
</div>
<script>
function addChatMessage() {
var chat = document.getElementById('Message'); // finds the container
var div = document.createElement('div');
div.id = "newMsg";
div.className = "container";
div.innerHTML = chat.value;
var parDiv = document.getElementById('chatMsg');
parDiv.appendChild(div);
}
</script>