title: How can I have form validation using JavaScript?
body: <p>I am trying to create a form that checks for JavaScript validation before it goes into my database basically if a user does not type in anything  then a alert will come up, however when viewing it in the browser, when I don't place any text inside any of the text boxes and hit submit, no alert comes up,  no nothing i'd appreciate it if you could help me out please</p>
  
  <h1>HTML</h1>
  
  <pre><code>&lt;body&gt;
  &lt;form action="update.php?eventID=&lt;?=$contact['eventID']?&gt;" name="myForm"  onsubmit="return validate()" method="post"&gt;
  
      &lt;label for="eventTitle"&gt;Event Title&lt;/label&gt;
      &lt;input type="text" name="eventTitle" value="?=$contact['eventTitle']?&gt;" id="eventTitle"&gt;
  
      &lt;label for="eventDescription"&gt;Event Description&lt;/label&gt;
      &lt;input type="text" name="eventDescription" value="&lt;?=$contact['eventDescription']?&gt;" id="eventDescription"&gt;
  
      &lt;label for="eventStartDate"&gt;Event Start Date&lt;/label&gt;
      &lt;input type="text" name="eventStartDate" value="&lt;?=$contact['eventStartDate']?&gt;" id="eventStartDate"&gt;
  
      &lt;label for="eventEndDate"&gt;Event End Date&lt;/label&gt;
      &lt;input type="text" name="eventEndDate" value="&lt;?=$contact['eventEndDate']?&gt;" id="eventEndDate"&gt;
  
      &lt;label for="eventPrice"&gt;Event Price&lt;/label&gt;
      &lt;input type="text" name="eventPrice" value="&lt;?=$contact['eventPrice']?&gt;" id="eventPrice"&gt;
  
      &lt;input type="submit" value="Update"&gt;
  
  &lt;/form&gt; 
  
  &lt;script src="update.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <h1>JavaScript</h1>
  
  <pre><code>function validate() {
       if( document.myForm.eventTitle.value == "" ) {
             alert( "Please enter a Event Title" );
              document.myForm.eventTitle.focus() ;
              return false; 
           }
  
           if( document.myForm.eventDescription.value == "" ) {
              alert( "Please enter a event Description!" );
              document.myForm.eventDescription.focus() ;
              return false;
           }
            if( document.myForm.eventStartDate.value == "" ) {
              alert( "Please enter a event Start Date!" );
              document.myForm.eventStartDate.focus() ;
               return false;
          }
            if( document.myForm.eventEndDate.value == "" ) {
              alert( "Please enter a event End Date!" );
              document.myForm.eventEndDate.focus() ;
              return false;
          }
  
           if( document.myForm.eventPrice.value == "" ) {
              alert( "Please enter a event End Date!" );
              document.myForm.eventPrice.focus() ;
             return false;
  
           }
            return( true );
       }
  </code></pre>