JSFiddle - React, Tailwind, and code Playground
HTML
<form name="myForm" action="demo_form" method="post" onsubmit="return f1()">
<button name="submit">submit</button>
</form>
JavaScript
x = 2;
function f1(){
if(x == 1) {
alert("Form could not be submited!");
return false;
}
else if(x == 2) {
return true;
}
}