title: show a div based on a conditional ajax result in php form
body: <p>I have a <code>PHP</code> form`looks like this</p>
  
  <pre><code>&lt;form&gt;
      &lt;div id="inid"&gt;
          National ID: &lt;input type="text" id="individual_nid" oninput="getIndividualName(this.value)" /&gt;
      &lt;/div&gt;
      &lt;hr /&gt;
      name: &lt;div id="individual_name_fetch"&gt;&lt;/div&gt;
      &lt;hr /&gt;
      &lt;div id="other_inputs fields" style="display: none;"&gt;
          more inputs fields...
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>In my <code>PHP</code> form I have an input <code>textbox</code> where the user inserts a number</p>
  
  <pre><code>&lt;input id="individual_nid" oninput="getIndividualName(this.value)" /&gt;
  </code></pre>
  
  <p>this <code>textbox</code> fires <strong>on the fly</strong> the following <code>ajax</code> function</p>
  
  <pre><code>function getIndividualName(val)
  {
      $.ajax({
          type: "POST",
          url:"get_individual_name.php",
          data: 'individual_nid='+val,
          success: function(data){
  
              $("#individual_name_fetch").html(data);
  
          }
      });
  }
  </code></pre>
  
  <p>in this function, I pass the user's input to the <code>get_individual_name.php</code> page.</p>
  
  <p>in the <code>get_individual_name.php</code> page, I have a <code>PHP</code> script that searches for the inserted number in the database and gets the corresponding individual name and fetches it to the <code>id="individual_name_fetch"</code> div.</p>
  
  <p>the <code>PHP</code> script in the <code>get_individual_name.php</code> page looks like this:</p>
  
  <pre><code>$q = mysqli_query($link, "SELECT * FROM table WHERE national_id = '".$_POST['individual_nid']."' ");
  if(mysqli_num_rows($q) == 1)
  {
      while($r = mysqli_fetch_assoc($q))
      {
          echo $individual_name = $r['individual_name'];
      }
  }
  else
  {
      echo $individual_name = 'Not in db';
  }
  </code></pre>
  
  <p><strong>up to here everything is fine</strong></p>
  
  <p>What I need to do now... </p>
  
  <p>If the searched user founded in the db <code>(mysqli_num_rows($q) == 1)</code> then I want to display the other inputs div <code>id="other_inputs fields"</code> in the form.  and if not, then the <code>other_inputs fields</code> div hides again</p>
  
  <p>How can I accomplish this?</p>
  
  <p><strong>please be aware that the <code>ajax</code> function and the <code>PHP</code> script run on the fly</strong></p>
  
  <hr>
  
  <p><strong><em>NOTE &amp; UPDATE</em></strong>
  the script's output will be <code>HTML</code> code, for example</p>
  
  <ol>
  <li>if the result found the output will be:</li>
  </ol>
  
  <p><code>&lt;span style="color: green;"&gt;&lt;i class="fa fa-check fa-fw fa-lg"&gt;&lt;/i&gt; &lt;?=$individual_name;?&gt;&lt;/span&gt;</code></p>
  
  <p>OR</p>
  
  <ol start="2">
  <li>in case no result found:</li>
  </ol>
  
  <p><code>&lt;span style="color: red;"&gt;&lt;i class="fa fa-times fa-fw fa-lg"&gt;&lt;/i&gt; No user found.&lt;/span&gt;</code></p>
  
  <p><strong>What</strong> I am thinking about is to assign a variable e.g. <code>$show_extra_fields = true</code> or <code>$show_extra_fields = false</code> and pass it back to the ajax function and from there I check the value of the $show_extra_fields variable and based on the value I show/hide the other fields div.</p>
  
  <p>is this possible?</p>