title: HTML form validation with Javascript
body: <p>im a bit new using javascript in HTML. I want to validate a HTML script using javascript however what i've written doesn't seem to work. Can anyone tell me where I'm going wrong???
  Here is the Javascript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function mandatoryFields()
  {
  var x=document.forms["add"]["contract_id"].value
  if (x==null || x=="")
    {
    alert("Please Enter the Contract Title");
    return false;
    }
  var x=document.forms["add"]["storydiv"].value
  if (x==null || x=="")
    {
    alert("Please Enter a Sprint");
    return false;
    }
  var x=document.forms["add"]["storydiv"].value
  if (x==null || x=="")
    { 
    alert("Please Enter a Story");
    return false
    }        
  var x=document.forms["add"]["date1"].value
  if ( x=="" || x==null) 
    { 
    alert("Please Enter a time");
    return false
    }  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>And here is the corresponding HTML script </p>
  
  <pre><code>&lt;form name="add" action="time-sheet/insert-time-sheet.php" method="post" onsubmit="return mandatoryFields()"&gt;
  &lt;table width="500" border="0" align="center" cellpadding="2" cellspacing="2"&gt;
    &lt;tr&gt;
      &lt;td colspan="2"&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td width="150"&gt;Select Date:&lt;/td&gt;
      &lt;td width="336"&gt;&lt;input name="date" type="text" value="YYYY-MM-DD" maxlength="100" class="datepick" id="date1" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Contract:&lt;/td&gt;
      &lt;td&gt;&lt;SELECT NAME="contract_id" onChange="getSprint(this.value)"&gt;&lt;OPTION VALUE=0&gt;--- Select Contract ---&lt;?php echo $options_contract?&gt;&lt;/SELECT&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Sprint:&lt;/td&gt;
      &lt;td&gt;&lt;div id="sprintdiv"&gt;&lt;select name="sprint" &gt;
      &lt;option&gt;--- Select Sprint ---&lt;/option&gt;
          &lt;/select&gt;&lt;/div&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Story:&lt;/td&gt;
      &lt;td&gt;&lt;div id="storydiv"&gt;&lt;select name="story"&gt;
      &lt;option&gt;--- Select Story ---&lt;/option&gt;
          &lt;/select&gt;&lt;/div&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dev Time:&lt;/td&gt;
      &lt;td&gt;&lt;input name="dev_time" size="20" onkeyup="ondalikSayiKontrol(this)" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;PM Time:&lt;/td&gt;
      &lt;td&gt;&lt;input name="pm_time" size="20" onkeyup="ondalikSayiKontrol(this)"/&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td colspan="2"&gt;&lt;table width="182" border="0" align="center" cellpadding="2" cellspacing="2"&gt;
        &lt;tr&gt;
  
          &lt;td width="68"&gt;&lt;input name="Submit" type="submit" id="Submit" value="Add Time Sheet" /&gt;&lt;/td&gt;
          &lt;td width="48"&gt;&lt;label&gt;
            &lt;input type="reset" name="reset" value="Reset" /&gt;
          &lt;/label&gt;&lt;/td&gt;
          &lt;td width="46"&gt;&lt;div align="center"&gt;&lt;a href="javascript:history.go(-1);"&gt;Back&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;input type="hidden" name="day" value="&lt;?php echo $day; ?&gt;" /&gt;
        &lt;input type="hidden" name="employee_id" value="&lt;?php echo $employee_id; ?&gt;" /&gt;
      &lt;/table&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td colspan="2"&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Thanks in advance!</p>