title: Html form onsubmit edit a text field in the form?
body: <p>I am learning php and html. </p>
  
  <p>I am trying to make a function run when a submit button is pressed. Then I want it to edit a text field on my form with the variable from that function. Without going to a new page...like a self refresh.</p>
  
  <p>How do I do this? Thanks.</p>
  
  <p>I think I have seen how to do this with JavaScript <code>getelementbyID</code>. But I need to do it via php. </p>
  
  <p>Perhaps an easy way to explain it is this: When button is pressed it generates a password in a text field automatically. </p>
  
  <p>The function I am using:</p>
  
  <pre><code>&lt;?
  function genkey($length){
      $key = '';
      list($usec, $sec) = explode(' ', microtime());
      mt_srand((float) $sec + ((float) $usec * 100000));
  
      $possibleinputs = array_merge(range('z','a'),range(0,9),range('A','Z'));
  
      for($i=0; $i&lt;$length; $i++) {
          $key .= $possibleinputs{mt_rand(0,61)}; }
      return $key;
  }
  ?&gt;
  </code></pre>