title: How to set focus on dropdown list, using javascript, php
body: <p>I am unable to set focus to my php page dc-test.php (this is a <strong>frames page</strong>: topFrame and botFrame) dropdown list, which has <strong>2 dropdown</strong> lists and are dependent. 
  These dropdown lists values are populated from a table.
  Unable to <strong>set focus for the first dropdown</strong> and later after the reload for the second dependent dropdown list. Pl see my code below, need your help ! Sorry if i am repeating this question on this forum, because I was unable to find the right answer.</p>
  
  <pre><code>    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
      &lt;html&gt;
      &lt;head&gt;
      &lt;SCRIPT language=JavaScript&gt;
      function reload(form)
      {
      var val=form.cat.options[form.cat.options.selectedIndex].value;
      self.location='dc-test.php?cat=' + val ;
      }
  
      function firstfield()
      {
      document.topFrame.cat.focus();
      }
      &lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body onLoad="firstfield();"&gt;
  
      &lt;?php
      $dbservertype='mysql';
      $servername='localhost';
      $dbusername='aaa';
      $dbpassword='234!@';
      $dbname='test';
  
      connecttodb($servername,$dbname,$dbusername,$dbpassword);
      function connecttodb($servername,$dbname,$dbuser,$dbpassword)
      {
      global $link;
      $link=mysql_connect ("$servername","$dbuser","$dbpassword");
      if(!$link){die("Could not connect to MySQL");}
      mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
      }
      // End of DB connection
  
      @$cat=$_GET['cat'];
      if(strlen($cat) &gt; 0 and !is_numeric($cat)){ 
      echo "Data Error";
      exit;
      }
  
  
      $quer2=mysql_query("SELECT DISTINCT Ac_desc, Ac_code FROM ACMAST order by Ac_desc");
  
  
      /////// Second drop down list we will check if category is selected else we will display all the subcategory/////
      if(isset($cat) and strlen($cat) &gt; 0){
      $quer=mysql_query("SELECT DISTINCT Add1 FROM ACMAST where Ac_code=$cat order by   Add1");
      }
  
      echo "&lt;form name='f1'&gt;";
      echo "&lt;table width='100%' height='39'  border='0' cellpadding='2' cellspacing='0'&gt;";
      echo "  &lt;tr&gt;";
      echo "    &lt;td width='12%'&gt;.&lt;/td&gt;";
      echo "    &lt;td width='7%'&gt;&lt;span class='sty1'&gt; Customer&lt;/span&gt;&lt;/td&gt;";
      echo "    &lt;td width='27%'&gt;&lt;select name='cat' onchange=\"reload(this.form);        showUser(this.value);\"&gt;
      &lt;option value=''&gt;Select Name&lt;/option&gt;";
      while($noticia2 = mysql_fetch_array($quer2)) {
      if($noticia2['Ac_code']==@$cat){echo "&lt;option selected value='$noticia2[Ac_code]'&gt;$noticia2[Ac_desc]&lt;/option&gt;"."&lt;BR&gt;";}
      else{echo  "&lt;option value='$noticia2[Ac_code]'&gt;$noticia2[Ac_desc]&lt;/option&gt;";}
      }
      echo "&lt;/select&gt;";
  
      echo "&lt;/td&gt;";
      echo "    &lt;td width='6%'&gt;&lt;span class='sty1'&gt;Address&lt;/span&gt;&lt;/td&gt;";
      echo "    &lt;td width='48%'&gt; &lt;/span&gt;&lt;select name='subcat'&gt;";
      while($noticia = mysql_fetch_array($quer)) {
      echo  "&lt;option value='$noticia[Add1]'&gt;$noticia[Add1]&lt;/option&gt;";
      }
      echo "&lt;/select&gt;";
      echo "&lt;/td&gt;";
      echo "  &lt;/tr&gt;";
      echo "&lt;/table&gt;";
      ?&gt;
      &lt;/body&gt;        
      &lt;/html&gt;
  </code></pre>