I am new to HTML and I am trying to create a script to display user input in a message box. I have created a textbox and validated it with a regular expression (alphabet only).
Now I need to display the user input in the page itself. How can I do this with JavaScript?
I need to display all the user inputs in the page itself. I need to display the two letter word in one container and three letter word in another container.
This is the code I tried.
<html>
<head>
<style type=text/css>
</style>
<script type=text/javascript>
function Allow() {
if (!user.title.value.match(/[a-zA-Z]$/) && user.title.value != ) {
user.title.value = ;
alert(Please Enter only alphabets);
}
}
var titles = [];
var titleInput = document.getElementById(title);
var messageBox = document.getElementById(display);
function insert( ) {
titles.push(titleInput.value);
clearAndShow();
}
function clearAndShow() {
// Clear our fields
titleInput.value = ;
// Show our output
messageBox.innerHTML = ;
messageBox.innerHTML += Titles: + titles.join(, ) + <br/>;
</script>
</head>
<body>
<p>form input</p>
<form name=user action= onsubmit= method=post>
User<input id=title type=text maxlength=4 onkeyup= Allow() >
<input type=submit value=Save/Show onclick= insert() />
</form>
<div id=display></div>
</form>
</body>
</html>