Reputation: 555
I am unable to set focus to my php page dc-test.php (this is a frames page: topFrame and botFrame) dropdown list, which has 2 dropdown lists and are dependent. These dropdown lists values are populated from a table. Unable to set focus for the first dropdown 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.
Pl look at function firstfield(), it does't set the focus to dropdown list in the below code.
<html>
<head>
<SCRIPT language=JavaScript>
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();
}
</script>
</head>
<body onLoad="firstfield();">
<?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) > 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) > 0){
$quer=mysql_query("SELECT DISTINCT Add1 FROM ACMAST where Ac_code=$cat order by Add1");
}
echo "<form name='f1'>";
echo "<table width='100%' height='39' border='0' cellpadding='2' cellspacing='0'>";
echo " <tr>";
echo " <td width='12%'>.</td>";
echo " <td width='7%'><span class='sty1'> Customer</span></td>";
echo " <td width='27%'><select name='cat' onchange=\"reload(this.form); showUser(this.value);\">
<option value=''>Select Name</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['Ac_code']==@$cat){echo "<option selected value='$noticia2[Ac_code]'>$noticia2[Ac_desc]</option>"."<BR>";}
else{echo "<option value='$noticia2[Ac_code]'>$noticia2[Ac_desc]</option>";}
}
echo "</select>";
echo "</td>";
echo " <td width='6%'><span class='sty1'>Address</span></td>";
echo " <td width='48%'> </span><select name='subcat'>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[Add1]'>$noticia[Add1]</option>";
}
echo "</select>";
echo "</td>";
echo " </tr>";
echo "</table>";
?>
</body>
</html>
Upvotes: 0
Views: 8566
Reputation: 3366
why don't you assign an id to your select box and then use
document.getElementById("cat").focus();
to access an element inside a frame use
window.frames[0].getElementById("cat").focus();
frames[0]
just change the number 0 to the index of your frame. e.g. if you have 2 frames and you want to access the second one it would be frames[1]
Upvotes: 1