I'm trying to make validate if an email form field is not empty, of course I'm learning by making mistakes, but some explanation is needed from any of You Pro guys.
Heres wat I have and it's not working, all do it looks logical to me.
<script>
document.getElementById('regform').addEventListener("submit", function(e))
{
if(document.querySelector("#mail")=='')
{
e.alert("You need to provide a valid email");
}
});
</script>
I'm kind of confused here.
This is the HTML:
<form class="login_form" id="regform" action="" method="post">
<input type="email" name="mail" id="mail" placeholder="Your @ email" required>
<input type="submit" value="INGRESAR">
</form>
<script>
document.getElementById('regform').addEventListener("submit", function(e))
{
if(document.querySelector("#mail").value == '')
{
e.alert("You need to provide a valid email");
}
}
</script>
get value from input text using document.querySelector("#mail").value anddocument.querySelector("#mail") only get element