JSFiddle - React, Tailwind, and code Playground
HTML
<form method="post" action="reg.php">
<input type="text" id="username" name="username"></input>
<button type="submit" onclick="return val()">Sign Up</button>
</form>
JavaScript
function val(){
var uname = document.getElementById('username').value;
if(!uname){
document.getElementById("error").innerHTML = "Enter a username";
alert("hello");
return false;
}
else{
return true;
}
}