title: Set value to a hidden field
body: <p>I have an instant search program which was collected from a <a href="http://www.codeforest.net/simple-search-with-php-jquery-and-mysql" rel="nofollow noreferrer">tutorial</a>
  . I modified some lines of the code. Here is the document :</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;link href=&quot;styles.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
      &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&gt;&lt;/script&gt;
      &lt;script type=&quot;text/javascript&quot;&gt;
          $(function() {
              $(&quot;.search_button&quot;).click(function() {
                  // getting the value that user typed
                  var searchString    = $(&quot;#search_box&quot;).val();
                  // forming the queryString
                  var data            = 'search='+ searchString;
  
                  // if searchString is not empty
                  if(searchString) {
                      // ajax call
                      $.ajax({
                          type: &quot;POST&quot;,
                          url: &quot;instant_search.php&quot;,
                          data: data,
                          beforeSend: function(html) { // this happens before actual call
                              $(&quot;.results&quot;).html('');
                              //$(&quot;#uname&quot;).value('');
                              //$(&quot;#searchresults&quot;).show();
                              $(&quot;.word&quot;).html(searchString);
                          },
                          success: function(html){ // this happens after we get results
                              $(&quot;.results&quot;).show();
                              $(&quot;.results&quot;).append(html);
                              $('#uname').value(html);
                              //document.getElementById('uname').value(html);
                              //$(&quot;#uname&quot;).value(html);
                          }
                      });
                  }
                  return false;
              });
          });
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php echo '&lt;center&gt;';?&gt;
  
      &lt;div class=&quot;header_box&quot;&gt;&lt;?php echo $f-&gt;SYSTEM_NAME; ?&gt;&lt;/div&gt;
  
  &lt;?php
  if($acc_type == 'admin'){ ?&gt;
      &lt;h1&gt;Create new admin account&lt;/h1&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;Username&lt;/td&gt;
              &lt;td&gt;:&lt;/td&gt;
              &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;id&quot; size=&quot;20&quot; class=&quot;text_box&quot;/&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type=&quot;button&quot; value=&quot;Check&quot;&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  
      &lt;?php
  }else if($acc_type == 'student'){ ?&gt;
      &lt;h1&gt;.:: Create student's account ::.&lt;/h1&gt;
      &lt;label style=&quot;font-size: 18px&quot;&gt;&lt;label style=&quot;color: red&quot;&gt;*&lt;/label&gt; Marked fields are must&lt;/label&gt;&lt;br/&gt;&lt;br/&gt;
  &lt;!--    &lt;form action=&quot;&quot; method=&quot;post&quot;&gt;--&gt;
      &lt;table border=&quot;0&quot;&gt;
          &lt;tr class=&quot;unimportant_text&quot;&gt;
              &lt;td&gt;Test Username&lt;/td&gt;
              &lt;td&gt;:&lt;/td&gt;
              &lt;td&gt;
                  &lt;form method=&quot;post&quot; action=&quot;instant_search.php&quot;&gt;
                      &lt;input type=&quot;text&quot; name=&quot;search&quot; id=&quot;search_box&quot; class=&quot;unimportant_text&quot;/&gt;
                      &lt;input type=&quot;submit&quot; class=&quot;search_button&quot; value=&quot;Check&quot; style=&quot;background: #808080; color: white; border: none&quot;/&gt;&lt;br /&gt;
                  &lt;/form&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Username&lt;label style=&quot;color: red&quot;&gt;*&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;:&lt;/td&gt;
              &lt;td&gt;
                  &lt;label class=&quot;results&quot; style=&quot;font-size: 20px; color: green; font-weight: bold&quot;&gt;&lt;/label&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;uname&quot; id=&quot;uname&quot;/&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Full Name&lt;label style=&quot;color: red&quot;&gt;*&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;:&lt;/td&gt;
              &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; class=&quot;text_box&quot;/&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Contact&lt;label style=&quot;color: red&quot;&gt;*&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;:&lt;/td&gt;
              &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; class=&quot;text_box&quot; /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Contact (Optional)&lt;/td&gt;
              &lt;td&gt;:&lt;/td&gt;
              &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; class=&quot;text_box&quot; /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Email&lt;/td&gt;
              &lt;td&gt;:&lt;/td&gt;
              &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; class=&quot;text_box&quot; /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Course&lt;label style=&quot;color: red&quot;&gt;*&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;:&lt;/td&gt;
              &lt;td&gt;
                  &lt;select name=&quot;course&quot;&gt;
                      &lt;?php
                      $courses = $f-&gt;get_courses();
                      foreach($courses as $c){ ?&gt;
                          &lt;option value=&quot;&lt;?php echo $c[1];?&gt;&quot;&gt;&lt;?php echo $c[1];?&gt;&lt;/option&gt;
                      &lt;?php
                      }
                      ?&gt;
  
                  &lt;/select&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Address&lt;/td&gt;
              &lt;td&gt;:&lt;/td&gt;
              &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; class=&quot;text_box&quot; /&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
          &lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;
  &lt;!--    &lt;/form&gt;--&gt;
      &lt;?php
  }
  ?&gt;
  &lt;?php echo '&lt;/center&gt;';?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>And here is my instant_search.php:</p>
  <pre><code>if (isset($_POST['search'])) {
  $word = mysql_real_escape_string($_POST['search']);
  $res = $f-&gt;select_name($word);
  if(mysql_num_rows($res) &gt; 0) {
      //echo 'Not available, choose another one';
  } else {
      echo $word;
  }
  }
  </code></pre>
  <p>What I want is very simple.</p>
  <ol>
  <li><p>I just want to check if the <code>$word</code> is available in database. If not then set that as value of a hidden field(uname). Then submit the form to another php file and create the account.</p>
  </li>
  <li><p>Here two form is being used, this is creating problem as well.</p>
  </li>
  </ol>
  <p>Please help me doing the job. Thanks in advance.</p>