Hi guys, Im working on my personal porfolio & thinking to add some web behaviour on my contact page.
Here’s my html code:
<div class="contact-form">
<h3>Leave a message:</h3>
<input type="text" placeholder="Name">
<input type="text" placeholder="Email">
<input type="text" placeholder="Subject">
<label for="email">
<textarea id="email" name="extra" cols="66" rows="7" placeholder="Message"></textarea>
</label>
<form>
<input type="submit" value="Send a message"/>
</form>
</div>
Here’s the JS code:
function sendButton() {
let greeting = alert("Thank you for you message 😊." + " I'll get back to you soon!");
}
let sendMsg = document.querySelector("form");
sendMsg.addEventListener("click", sendButton);
For some reasons, my JS code keep appearing error (“ Uncaught TypeError: Cannot read property ‘addEventListener’ of null ”). I double checked the code and still cannot figure out where i went wrong. Please help me debug this, thanks🙏