title: How to make an entry in a text box required when one specific radio button is selected?
body: <p>I have several radio buttons which can be chosen and then the form can be sent without an issue. However a user can easily select the "Other" radio button and submit without giving any context or reason on why they chose it leaving the people receiving the "completed" form guessing what the issue is.</p>
  
  <p>What I want to happen is that if a person selects the "Other" radio button and try and submit without a note/message/comment they will be interrupted with a requirement massage.</p>
  
  <p>The snippet of the form that I want this to happen to is:</p>
  
  <pre><code>&lt;label&gt;
      &lt;input name="category" type="radio" value="Other" checked&gt;Other
  &lt;/label&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
  Note: &lt;br&gt; &lt;textarea name="comment" rows="10" cols="70" placeholder="More detail... (Is there a way to recreate the error? What happened?)"&gt;&lt;/textarea&gt;   
  &lt;br&gt;&lt;br&gt;
  &lt;input type="submit" name="submit" value="Submit" class="userFriendly"&gt; 
  </code></pre>
  
  <p>I have tried many variations of if statements and the required function given with HTML5 but can not seem to get what I need.</p>
  
  <p>Any help will be appreciated and thanks in advance. </p>
  
  <p><strong>Edit 1:</strong>
  Here is the full code of my form:</p>
  
  <pre><code>&lt;form action="send_form_email.php?OperationID=&lt;?php print ($OperationID) ?&gt;&amp;title=&lt;?php print ($title) ?&gt;" method="post" onsubmit="return this.users.value != ''"&gt; 
          &lt;table&gt;
          &lt;tr&gt;
             &lt;td&gt;Name:&lt;/td&gt; 
             &lt;td&gt;
             &lt;select required name="users"&gt; 
             &lt;option value=""&gt;&lt;/option&gt;
             &lt;?php
             foreach($users as $key =&gt; $value){
             echo "&lt;option value=\"$key\"&gt;$key&lt;/option&gt;";
             }
             ?&gt;
             &lt;/select&gt;
             &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
             &lt;td &lt;?php print $hiddenJobDiv ?&gt;&gt;Job Number:&lt;/td&gt; 
             &lt;td&gt;&lt;input type="text" name="jobid" value="&lt;?php echo ($jobid) ?&gt;" &lt;?php echo $disabledInput ?&gt;&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
             &lt;td &lt;?php print $hiddenPartDiv ?&gt;&gt;Part Number:&lt;/td&gt; 
             &lt;td&gt;&lt;input type="text" name="partid" value="&lt;?php echo ($part_id) ?&gt;" &lt;?php echo $disabledInput ?&gt;&gt;&lt;/td&gt;
          &lt;/tr&gt;
             &lt;?php if ($OperationID == 20){ ?&gt;
               &lt;tr&gt;
                 &lt;td&gt;Machine:&lt;/td&gt; 
                 &lt;td&gt;&lt;input type="text" name="mach" value="&lt;?php echo ($machCode) ?&gt;" &lt;?php echo $disabledInput ?&gt;&gt;&lt;/td&gt;
               &lt;tr&gt;
             &lt;?php } ?&gt;
          &lt;/table&gt;&lt;br&gt;
          Error:&lt;br&gt;&lt;br&gt;&lt;br&gt;                                                                                                                                        &lt;!-- Display of dynamic list. --&gt;
          &lt;?php
          $html = customErr($OperationID);                                                                                                                          
          foreach ($html as $oneError):?&gt;                                                                                                                           &lt;!-- foreach used to find the next iteration of the array. --&gt;
          &lt;label&gt;                                                                                                                                                   &lt;!-- Beginning of the dynamic radio button list. --&gt;
              &lt;input name="category"                                                                                                                                
              type="radio"
              value="&lt;?php echo $oneError; ?&gt;"&gt;                                                                                                                     &lt;!-- Dynamic value to be used in Slack API and email. --&gt;
              &lt;?php echo $oneError; ?&gt;                                                                                                                              &lt;!-- Dynamic value as a visual representation for user. --&gt;
          &lt;/label&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
          &lt;?endforeach;?&gt;                                                                                                                                           &lt;!-- Stops foreach and goes to next object if avaliable. --&gt;
          &lt;label&gt;                                                                                                                                                   &lt;!-- A permanent radio button labeled "Other" for (cont.) --&gt;
          &lt;input name="category" type="radio" value="Other" checked&gt;Other                                                                                           &lt;!-- all report error forms. --&gt;
          &lt;/label&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
          &lt;?php
          if (isset($_POST['category'])=="Other" &amp;&amp; isset($_POST["comment"])=="") 
          {
              $required[] = ("You must write a note if you choose \'other\'.");
          }
          return $required;
          ?&gt;
          Note: &lt;?php echo $required ?&gt; &lt;br&gt; &lt;textarea name="comment" rows="10" cols="70"
          placeholder="More detail... (Is there a way to recreate the error? What happened?)"&gt;&lt;/textarea&gt;    &lt;!-- Allows the user to type in a custom message/note. --&gt;
          &lt;br&gt;&lt;br&gt;
  
          &lt;input type="submit" name="submit" value="Submit" class="userFriendly"&gt;                                                                                   &lt;!-- A large 'submit' button for touch screen. --&gt;
          &lt;a href="#" onclick="close_window();return false;"&gt;&lt;input type="submit" name="close" value="Close" class="userFriendly"&gt;&lt;/a&gt;                              &lt;!-- A large 'close' button for touch screens. --&gt;
      &lt;/form&gt; 
  </code></pre>
  
  <p><strong>Edit 2:</strong>
  Here is the full code:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt; 
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css" href="/css/main_style.css"&gt;
  &lt;style&gt;
  .error {color: #FF0000;}
  table, th, td {border: 1px solid white;}
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt; 
  
  &lt;script&gt;
  function close_window() {
      close();
  }
  &lt;/script&gt;
  
  &lt;?php
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
  include("includes/classes.php");
  include("includes/classes_monitoring.php"); 
  $link = open_v8_db();
  $users = get_clocked_in_users();
  $OperationID = @$_REQUEST['OperationID'];
  
  $title = "";
  $grayedOut = false;
  $disabledInput = "";
  $hiddenJobDiv = "";
  $hiddenPartDiv = "";
  $ID = "";
  $html = "";
  
  $jobid    = @$_REQUEST['JobID'];
  $part_id  = @$_REQUEST['PartID'];
  $machCode = @$_REQUEST['Machine'];
  
  if ($OperationID == 20)
  {   
      $title = "Punching Machine";
      $grayedOut = true;
  }
  elseif ($OperationID == 30)
  {
      $title = "Folding Machine";
      $grayedOut = true;
  }
  elseif ($OperationID == 40 || $OperationID == 140)
  {
      $title = "Powder Coating";
      $grayedOut = true;
  }
  elseif ($OperationID == 50 || $OperationID == 150)
  {
      $title = "Assembly";
      $grayedOut = true;
  }
  elseif ($OperationID == 60 || $OperationID == 160)
  {
      $title = "Inspection";
      $grayedOut = true;
  }
  elseif ($jobid != "" &amp;&amp; $part_id == "")
  {
      $title = "Job";
      $OperationID = 70;
  }
  else
  {
      $title = "General";
      $OperationID = 80;
      $grayedOut = false;
  }
  
  if ($greyedOut = true)
  {
      $disabledInput = "readonly";
  }
  
  function customErr($ID)
  {
      $html = "";
      $issueReport_folder = 'document/Production System/';
      $issueReporting = $issueReport_folder.'IssueReporting.csv';
      $file_handle = fopen($issueReporting, "r");
  
      if ($ID == 20)
      {
          while (!feof($file_handle))
          {
              $line_of_text = fgetcsv($file_handle, 1024);
              if ($line_of_text[2] == "Punch")
              {
                  $html[] = $line_of_text[1];
              }
          }
      }
      if ($ID == 30)
      {
          while (!feof($file_handle))
          {
              $line_of_text = fgetcsv($file_handle, 1024);
              if ($line_of_text[2] == "Fold")
              {
                  $html[] = $line_of_text[1];
              }
          }
      }
      if ($ID == 40 || $ID == 140)
      {
          while (!feof($file_handle))
          {
              $line_of_text = fgetcsv($file_handle, 1024);
              if ($line_of_text[2] == "Powder")
              {
                  $html[] = $line_of_text[1];
              }
          }
      }
      if ($ID == 50 || $ID == 150)
      {
          while (!feof($file_handle))
          {
              $line_of_text = fgetcsv($file_handle, 1024);
              if ($line_of_text[2] == "Assembly")
              {
                  $html[] = $line_of_text[1];
              }
          }
      }
      if ($ID == 60 || $ID == 160)
      {
          while (!feof($file_handle))
          {
              $line_of_text = fgetcsv($file_handle, 1024);
              if ($line_of_text[2] == "Inspectoin")
              {
                  $html[] = $line_of_text[1];
              }
          }
      }
      if ($ID == 70)
      {
          while (!feof($file_handle))
          {
              $line_of_text = fgetcsv($file_handle, 1024);
              if ($line_of_text[2] == "Job")
              {
                  $html[] = $line_of_text[1];
              }
          }
      }
      if ($ID == 80)
      {
          while (!feof($file_handle))
          {
              $line_of_text = fgetcsv($file_handle, 1024);
              if ($line_of_text[2] == "General")
              {
                  $html[] = $line_of_text[1];
              }
          }
      }
      fclose($file_handle);
      return $html;
  }
  
  $jobErr = $partErr = $machErr = "";
  $job = $part = $mach = $note = "";
  
  if ($jobid == "")
  {
      $hiddenJobDiv = "style=\"display:none;";
  }
  if ($part_id == "")
  {
      $hiddenPartDiv = "style=\"display:none;";   
  }
  
  function test_input($data) 
  {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      return $data;
  }
  ?&gt;
  &lt;div class="reportForm"&gt;                                                                                                                
      &lt;h2&gt;Report &lt;u&gt;&lt;?php echo $title; ?&gt;&lt;/u&gt; Error&lt;/h2&gt;
      &lt;form action="send_form_email.php?OperationID=&lt;?php print ($OperationID) ?&gt;&amp;title=&lt;?php print ($title) ?&gt;" method="post" onsubmit="return this.users.value != ''"&gt; 
          &lt;table&gt;
          &lt;tr&gt;
             &lt;td&gt;Name:&lt;/td&gt; 
             &lt;td&gt;
             &lt;select required name="users"&gt; 
             &lt;option value=""&gt;&lt;/option&gt;
             &lt;?php
             foreach($users as $key =&gt; $value){
             echo "&lt;option value=\"$key\"&gt;$key&lt;/option&gt;";
             }
             ?&gt;
             &lt;/select&gt;
             &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
             &lt;td &lt;?php print $hiddenJobDiv ?&gt;&gt;Job Number:&lt;/td&gt; 
             &lt;td&gt;&lt;input type="text" name="jobid" value="&lt;?php echo ($jobid) ?&gt;" &lt;?php echo $disabledInput ?&gt;&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
             &lt;td &lt;?php print $hiddenPartDiv ?&gt;&gt;Part Number:&lt;/td&gt; 
             &lt;td&gt;&lt;input type="text" name="partid" value="&lt;?php echo ($part_id) ?&gt;" &lt;?php echo $disabledInput ?&gt;&gt;&lt;/td&gt;
          &lt;/tr&gt;
             &lt;?php if ($OperationID == 20){ ?&gt;
               &lt;tr&gt;
                 &lt;td&gt;Machine:&lt;/td&gt; 
                 &lt;td&gt;&lt;input type="text" name="mach" value="&lt;?php echo ($machCode) ?&gt;" &lt;?php echo $disabledInput ?&gt;&gt;&lt;/td&gt;
               &lt;tr&gt;
             &lt;?php } ?&gt;
          &lt;/table&gt;&lt;br&gt;
          Error:&lt;br&gt;&lt;br&gt;&lt;br&gt;                                                                                                                                        &lt;!-- Display of dynamic list. --&gt;
          &lt;?php
          $html = customErr($OperationID);                                                                                                                          
          foreach ($html as $oneError):?&gt;                                                                                                                           &lt;!-- foreach used to find the next iteration of the array. --&gt;
          &lt;label&gt;                                                                                                                                                   &lt;!-- Beginning of the dynamic radio button list. --&gt;
              &lt;input name="category"                                                                                                                                
              type="radio"
              value="&lt;?php echo $oneError; ?&gt;"&gt;                                                                                                                     &lt;!-- Dynamic value to be used in Slack API and email. --&gt;
              &lt;?php echo $oneError; ?&gt;                                                                                                                              &lt;!-- Dynamic value as a visual representation for user. --&gt;
          &lt;/label&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
          &lt;?endforeach;?&gt;                                                                                                                                           &lt;!-- Stops foreach and goes to next object if avaliable. --&gt;
          &lt;label&gt;                                                                                                                                                   &lt;!-- A permanent radio button labeled "Other" for (cont.) --&gt;
          &lt;input name="category" type="radio" value="Other" checked&gt;Other                                                                                           &lt;!-- all report error forms. --&gt;
          &lt;/label&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
          &lt;?php
          if (isset($_POST['category'])=="Other" &amp;&amp; isset($_POST["comment"])=="") 
          {
              $required[] = ("You must write a note if you choose \'other\'.");
          }
          return $required;
          ?&gt;
          Note: &lt;?php echo $required ?&gt; &lt;br&gt; &lt;textarea name="comment" rows="10" cols="70"
          placeholder="More detail... (Is there a way to recreate the error? What happened?)"&gt;&lt;/textarea&gt;    &lt;!-- Allows the user to type in a custom message/note. --&gt;
          &lt;br&gt;&lt;br&gt;
  
          &lt;input type="submit" name="submit" value="Submit" class="userFriendly"&gt;                                                                                   &lt;!-- A large 'submit' button for touch screen. --&gt;
          &lt;a href="#" onclick="close_window();return false;"&gt;&lt;input type="submit" name="close" value="Close" class="userFriendly"&gt;&lt;/a&gt;                              &lt;!-- A large 'close' button for touch screens. --&gt;
      &lt;/form&gt;                                                                                                                                                       &lt;!-- End of form. --&gt;
  &lt;/div&gt;                                                                                                                                                            
  &lt;/body&gt;                                                                                                                                                           
  &lt;/html&gt;
  </code></pre>