0

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>

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

thank you so much ..but can you please explain why .innerText does not work..?
I suppose you were using Firefox? Because Firefox is the only browser that doesn't support the .innerText property apparently :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.