title: Setting the value of an HTML textbox using Javascript inside of a PHP block (using echo)
body: <p>I'm trying to run a MySQL query depending on what HTML selectbox option is selected and then take the query result and output it to an HTML textbox but to no avail. I'm using the switch statement with the superglobal $_GET. I'm trying to set the value of an HTML textbox using Javascript inside of a PHP block (using echo), but it's not working. The textbox is not being populated (still blank). Could this be because the PHP is running before the textbox is getting initialized or is there something else I'm missing? I know for sure that the DB login info is correct, and the query actually works. The code is below.</p>
  
  <pre><code>&lt;?php
  ---db login info here---
  
  switch($_GET['string'])
  {
      case "another string":
          $query = mysql_query("SELECT field1 FROM table1 WHERE id = '1'");
          $row = mysql_fetch_row($query);
          break;
  }
  
  echo "&lt;script type='text/javascript'&gt;";
  echo "document.getElementById('textbox').value = '$row[0]'";
  echo "&lt;/script&gt;";   
  ?&gt;
  </code></pre>