menu

arrow_back Enter in the field without buttons?

by
0 votes
How to send by pressing Enter without a button?
<textarea id="WebChatTextID" placeholder="Введите сообщение и нажминете Enter"></textarea>
<div id="WebChatFormForm" ></div>
<div id="answer_div" ></div>

<script>
function strip(html)
{
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || "";
}
var input = document.getElementById("WebChatTextID");
input.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode === 13) {
alert =typeof window.web_send_msg()
}
})
function web_send_msg()
{
var message = $("#WebChatTextID").val();

//var name = $("#WebChatNameID").val();

$("#WebChatTextID").val("");

$("#WebChatFormForm").append("<p><b>"+strip(name)+": </b>"+message+"</p>");

CometServer().web_pipe_send("web_chat_pipe", {"text":message, "name":name});
}


$(document).ready(function()
{
CometServer().start({dev_id:1}) // Подключаемся к комет серверу

CometServer().subscription("web_chat_pipe", function(msg)
{
console.log(msg)
$("#WebChatFormForm").append("<p><b>"+strip(msg.data.name)+": </b>"+msg.data.text+"</p>");
});
});
</script>
</body>
</html>

2 Comments

Sedbol if the answer helped, please mark it as solution.
Thank you the issue has been resolved!!!!!!

1 Answer

by
 
Best answer
0 votes
Wrap the whole thing in <form></form>