I would like that the code below show an alert when an input email contains both "@
" and ".com
" when the submit button is clicked.
Currently, the alert is not showing up. Not sure whether the error has to do with the submit button or not.
function myFunction() {
const email = document.getElementById("e").value;
var button = document.getElementById("s").onclick;
if (email.includes('@') && (button.clicked == true)) {
alert("Thank you for subscribing!");
} else {
alert("Please enter a valid email.")
}
}
input {
border: 0;
padding: 10px;
font-size: 18px;
}
input[type="submit"] {
background: red;
color: white;
border: solid black;
}
<input type="email" placeholder="Your email" id="e">
<input type="submit" id="s">