I am relatively new to the world of coding, but I have already delved into HTML, CSS, and basic DOM scripting.
My goal is simple - I want to create a comment box where people can leave messages like in a guestbook. However, when I input text and click on 'comment', nothing seems to happen. How can I enable users to type a message and see it displayed below? Any help with this issue would be greatly appreciated!
If anyone has encountered this problem before and knows how to solve it, please share your insights.
function fn1() {
var str = document.getElementById("text1").value;
alert("Thank you!");
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: white;
font-family: sans-serif;
/*
background-image: url(guest.jpg);
background-size: 450px;
*/
}
.container {
width: 600px;
border: 2px solid black;
padding: 15px 10px;
}
.container h2 {
text-align: center;
margin-bottom: 15px;
}
textarea {
height: 25px;
width: 100%;
border: none;
border-bottom: 2px solid gray;
background-color: transparent;
margin-bottom: 10px;
resize: none;
outline: none;
transition: .5s
}
.btn button {
padding: 10px 15px;
border: none;
outline: none;
border-radius: 5px;
text-transform: uppercase;
font-weight: bold;
cursor: pointer;
color: white;
background-color: orange;
}
button {
color: gray;
background-color: lightgray;
}
<!DOCTYPE html>
<html>
<head>
<title>Visitor comment</title>
<link rel="stylesheet" type="text/css" href="visitor.css">
</head>
<body>
<div class="container">
<h2>Leave Us a Comment</h2>
<form>
<textarea id="text1" placeholder="Add Your Comment"></textarea>
<div class="btn">
<button onclick="fn1()" id="btn1">Comment</button>
<!-- <button>Cancel</button> -->
</div>
</form>
</div>
<p id="result"></p>
<script type="visitor.js"></script>
</body>
</html>