I've got a function to show an alert if two elements aren't filled out, but the alert isn't showing up and it's just reloading the page. Not sure what I've missed or where I'm going wrong. Here is the Javascript:
function submitNewsletter() {
var name = document.getElementById("name");
var email = document.getElementById("email");
if (name == "" || email == "") {
alert("Please fill in your details.");
return false;
}
}
And here is the html it's for:
<section class="signup">
<h1>Keep up to date.</h1>
<p>Sign up to our newsletter to hear about improvements and additions to Electric Dreams.</p>
<form class="newsletterForm">
<label for="name" class="label">Full Name</label>
<input type="text" id="name" name="name" class="input" placeholder="Full Name"> <br>
<label for="email" class="label">Email Address</label>
<input type="email" id="email" name="email" class="inout" placeholder="Email Address"> <br>
<button type="submit" class="btn" onclick="submitNewsletter()">Submit</button>
</form>
</section>