How to prevent a form from submit if text box is empty?
This I have done in JSP successfully using alert message.
Javascript:
function validate()
{
var x=document.forms["Form1"]["comp"].value;
if (x==null || x=="")
{
alert("comp cannot be blank");
return false;
}
<form name="Form" action="welcome.php" onsubmit="return validate()" method="post">
<input type="text" name="comp">
How can I do the same using PHP? So that whenever a user submits without entering text it should give message to user through an javascript alert() message.
I can display alert message:
echo '<script language="javascript">alert("comp cant blank");</script>';
But how can i give condition?what are the changes has to be made in the above please put it in a code form.i have to do it only in PHP.