title: alert message on submit if text box is empty using PHP
body: <p>How to prevent a form from submit if text box is empty? </p>
  
  <p>This I have done in JSP successfully using alert message.</p>
  
  <p>Javascript:</p>
  
  <pre><code> function validate()
   {
     var x=document.forms["Form1"]["comp"].value;
     if (x==null || x=="")
     {
       alert("comp cannot be blank");
       return false;
     }
  
     &lt;form name="Form" action="welcome.php" onsubmit="return validate()"  method="post"&gt;
        &lt;input type="text" name="comp"&gt;
  </code></pre>
  
  <p>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 <code>alert()</code> message.</p>
  
  <p>I can display alert message:</p>
  
  <pre><code>echo  '&lt;script language="javascript"&gt;alert("comp cant blank");&lt;/script&gt;';
  </code></pre>
  
  <p>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.</p>