JSFiddle - React, Tailwind, and code Playground
HTML
<form method="post" action="something.html">
<input type="text" id="blah1" class="required" /><br/>
<input type="text" id="blah2" class="required" /><br/>
<input type="text" id="blah3" class="required" /><br/>
<input type="text" id="blah4" class="required" /><br/><br/>
<a href="#" onclick="insert();">submit</a>
<button type="submit" onclick="insert();">submit</button>
</form>
JavaScript
function insert() {
var flagInvalid = false;
var tempArray = document.getElementsByClassName("required");
for (var i = 0; i < tempArray.length; i++)
{
if (tempArray[i].value == ""){
flagInvalid = true;
break;
}
}
if (flagInvalid == false) {
alert ("sending ajax call.");
} else {
alert ("Please enter all required fields.");
}
}