Pressing enter in the textbox makes no sense to me, so I'm trying to guess what you want.
Sending a form
If you have something like this:
<form method="post" id="theForm">
<div id="hudid" class="hudclass">
<input type="text" name="hud" id="hudinput" class="hud-input" placeholder="Enter text here..." maxlength="140">
</div>
</form>
and you want to send this form, just call document.getElementById("theForm").submit()
in your setInterval
function.
Since you're using setInterval
, you may also want to see ajax
. jQuery.ajax is a good first choice.
Appending a new line
Are you trying to appending a new line in a textbox? No, <input type="text">
is not a multiline textbox. You would like to use a <textarea>
.
And if you want to append a new line, you can just append a new line and focus instead of pressing enter in it.
setInterval(function () {
document.getElementById('hudinput').value = Math.random().toString(36).substring(2, 15);
document.getElementById('hudinput').value += "\n";
document.getElementById('hudinput').focus();
}, 5000);
<textarea id="hudinput" class="hud-input" placeholder="Enter text here..." maxlength="140" cols="40" rows="5"></textarea>