title: How to assign a value to a textbox by onclick button?
body: <p>I am generating passwords automatically by using php. I stored the generated password in a variable. Here i have assign those generated passwords to a text box by using ONCLICK property on button(button name is "Generate Password"). But i am not getting required output(password must be visible in textbox by clicking that button). Here i have attached respective code. Can anyone tell  what i had done wrong??</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;head&gt;
  &lt;title&gt;create_profile&lt;/title&gt;
  &lt;link rel="stylesheet" type="text/css" href="create_profile.css" /&gt;
   &lt;script type="text/javascript"&gt;
  
          function getPassword(){
          document.getElementById("password").value="&lt;?php
  
      // Characters to use for the password
      $str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  
      // Desired length of the password
      $pwlen = 8;
  
      // Length of the string to take characters from
      $len = strlen($str);
  
      // RANDOM.ORG - We are pulling our list of random numbers as a
      // single request, instead of iterating over each character individually
      $uri = "http://www.random.org/integers/?";
      $random = file_get_contents(
          $uri ."num=$pwlen&amp;min=0&amp;max=".($len-1)."&amp;col=1&amp;base=10&amp;format=plain&amp;rnd=new"
      );
      $indexes = explode("\n", $random);
      array_pop($indexes);
  
      // We now have an array of random indexes which we will use to build our password
      $pw = '';
      foreach ($indexes as $int){
          $pw .= substr($str, $int, 1);
  
      }
  </code></pre>
  
  <p>echo $pw;</p>
  
  <p>?>";
              }</p>
  
  <pre><code>    &lt;/script&gt;
  </code></pre>
  
  <p>
  </p>
  
  <pre><code>    &lt;h1&gt; Create Profile &lt;/h1&gt;
  
      &lt;label for="name"&gt;name:&lt;/label&gt;&lt;br /&gt;
      &lt;input id="name" name="name" type="text" size="30" /&gt;&lt;br /&gt;
  
      &lt;label for="user_id"&gt;user id:&lt;/label&gt;&lt;br /&gt;
      &lt;input id="user_id" name="user_id" type="text" size="30" /&gt;&lt;br /&gt;
  
      &lt;label for="email"&gt;Your Email:&lt;/label&gt;&lt;br /&gt;
      &lt;input id="email" name="email" type="text" size="60" /&gt;&lt;br /&gt;
  
  
  
  
      &lt;label for="password"&gt;password:&lt;/label&gt;&lt;br /&gt;
      &lt;input id="password" name="password" size = "10" /&gt; &lt;br/&gt;
      &lt;button onclick="getpassword();" &gt;Generate Password&lt;/button&gt;
  </code></pre>
  
  <p>
  </p>