Today I will be teaching you how to display a users text box input using only HTML, CSS and JavaScript
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<div>
Input your message: <input type="text" name="message" id="userMessage"> <br>
<button type="button" id="submitBtn">Submit</button>
<p>Your message is: <span id="userMessageDisplay"> </span></p>
<script src="script.js"></script>
</div>
</body>
</html>
JavaScript
let userMessage = document.getElementById('userMessage');
let submitBtn = document.getElementById('submitBtn');
let messageDisplay = document.getElementById('userMessageDisplay');
submitBtn.addEventListener('click', displayMessageFunction);
function displayMessageFunction(){
messageDisplay.innerHTML = userMessage.value;
}
If you found this blog post helpful don’t forget to check out my other projects and if you want more content follow me on
YouTube: https://www.youtube.com/channel/UC2nxqB2usQIS2c8zwVZKWEQ
Instagram: https://www.instagram.com/coding_for_the_web/
Twitter: https://twitter.com/LearnWebCoding
Comments