title: php, html combobox and textfield
body: <p>I made a simple application that have a combobox which is loaded with database value and a textfield which should display text related to combo box selection.
  Name        Number
  number1     1234
  number2     2345
  number2     5678
  number3     2212</p>
  
  <p>So combo box will have values number1, number2, number3. when user selects number1, i have to load textfield value with 1234 and if number2 is selected 2345,5678. </p>
  
  <p>Below is my code which retrieves from database ... but problem is the value is loaded only when i press enter key instead of clicking submit button...</p>
  
  <pre><code>&lt;head&gt;
      &lt;title&gt;Sample Numbers&lt;/title&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
  &lt;/head&gt;
  &lt;body &gt;
      &lt;?php
      $dbname = 'sample_db';
      $db_user = 'xxx';
      $db_pass = 'xxx';
      $host = 'localhost';
      $conn = mysql_connect($host, $db_user, $db_pass);
      mysql_select_db($dbname);
      $query = "select distinct Name from numbers";
      $result = mysql_query($query, $conn) or die(mysql_error());
      ?&gt;
      &lt;center&gt;
          &lt;form name=callsubm&gt;
              &lt;table&gt;
                  &lt;?php
                  if ($result) {
                  ?&gt;
                      &lt;tr&gt;
                          &lt;td&gt;Group Name:&lt;/td&gt;
                          &lt;td&gt;&lt;select name="Name" id="Name" onchange="onComboChange();"&gt;
                          &lt;?php
                              while ($row = mysql_fetch_assoc($result)) {
                                  echo '&lt;option value="' . $row['Name'] . '"&gt;' . $row['Name'] . '&lt;/option&gt;';
                              }
                           }
                              ?&gt;
                          &lt;/select&gt;
                          &lt;?php
                          if (isset($_GET['Name'])) {
                              $array = array();
                              $query = "select Number from numbers where Name='" . $_GET['Name'] . "'";
                              $result = mysql_query($query, $conn) or die(mysql_error());
                              $i = 0;
                              if ($result) {
                                  while ($row = mysql_fetch_assoc($result)) {
                                      $array[] = $row['Number'];
                                      $i++;
                                  }
                              }
                              $total_numbers = implode(',', $array);
                          }
                          ?&gt;
                          &lt;script type="text/javascript"&gt;
                              function showValues() {
                                  var a=new Array();
             &lt;?php
                                    for ($i = 0; $i &lt; count($array); $i++) {
                                         echo "a[$i]='" . $array[$i] . "';\n";
                                    }
      ?&gt;
                                    alert(a.join());
                                    document.getElementById("inTxt").value=a.join();
                              }
                          &lt;/script&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Numbers :&lt;/td&gt;
                      &lt;td &gt;&lt;input name=inTxt id=inTxt type="text" size="15"&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="button" id="callBtn" name="callBtn" value="submit" onclick="showValues()" &gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/form&gt;
      &lt;/center&gt;
      &lt;script type="text/javascript"&gt;
          function onComboChange() {
           groupName=document.getElementById("Name").value;
           alert("Selected Group:" + groupName);
      }
      &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>How to solve this? </p>
  
  <p>Thanks in advance</p>