I have integrated JS and HTML code. The issue I am facing is that upon submission, the entire page is being submitted instead of just my form.
function submit_by_id()
{
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
if (!validation()) // Validation function call
{
return false;
}
else
{
alert("All good");
return true;
}
}
Form validation function currently checks for email and password.
function validation()
{
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
if (name === '' || email === '')
{
alert("Please fill out all fields!");
return false;
}
else
{
return true;
}
}
Below is the HTML code
<form name ="myform" id="myform" onsubmit=" return submit_by_id()" action="#">
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name">
</div>
<button type="Submit" class="btn btn-primary">Submit</button>
</form>