Below function check if form text box is blank .If the text box is left blank, an alerts message is display as popup on the web pages, and function returns false, and the form will not be submitted:
if (x==null || x=="")
alert("Please enter the name.");
<form name="contact" action="demo.php" onsubmit="return validateForm()"
First name: <input type="text" id="name" name="name">
<input type="submit" name="submit" value="Submit">
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.