Hadi
Hadi

Reputation: 23

Onclick button input does not work

This below code is like a chat page.There are a text type input and button type input at the bottom of the page which are fixed.My idea is whenever i write something in text input and then click on button the message goes to a new created div. but it does not work .Any help would be appreciated. thanks

<script>
    function updatePageMsg() {
        var msg = document.getElementById("Text").value;
        var divElement = document.createElement("div");

        divElement.setAttribute("style", "background-size:cover; padding: 5px 5px 5px 5px ;width:200px;height:200px");

        var pElement = document.createElement("p");

        pElement.innerText = msg;
        divElement.appendChild(pElement);
        rightDiv = document.getElementById("rightdiv");
        rightDiv.appendChild(divElement);
    }
</script>

<div style="margin-top:50px ; background-size:cover;background-attachment:fixed;position:absolute;top:0;left:0;right:0;bottom:0"">

    <div id="rightdiv" style="width:30%;left:0 ; height:100% ; background-color:yellow;float:left ; overflow:scroll"></div>
    <div style="width:70%;right:0 ; height:100% ; background-color:red;float:left ; overflow:scroll"></div>
</div>

<div style="position:fixed ; bottom:3px ; width:100% ; background-size:cover; left:0 ;text-align:center">
    <div>
        <input id="Text" type="search" value="Enter your Message here"  style="font-size:20px"  size="100"/>
        <input onclick="updatePageMsg()" id="SendBtn" type="button" value="Send" style="font-size:20px ; bottom:6px"   />

    </div>
</div>

Upvotes: 0

Views: 67

Answers (1)

Jiř&#237; Kantor
Jiř&#237; Kantor

Reputation: 762

Use pElement.innerHTML = msg; instead of pElement.innerText = msg;

Upvotes: 1

Related Questions