Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onchange in select form

Status
Not open for further replies.

AIX5L

Technical User
Joined
Jul 27, 2001
Messages
228
Location
CH
Hi

Im newbie in PHP

I know that i cant't do a onchange function in php to generate dynamic selects.

My problem is that i want to have 2 select boxes.

box1 is category
box 2 is subcategory

each subcategroy has its parent category
I wont to select the category ( ex people )in box 1 and want to see in box 2 ( ex Womens )
Can anybody give me a good example to do this in the same php-script ?



box1:

echo &quot;<select size=1 name=kat>&quot;;

while (odbc_fetch_row($kategorie);
{
$kategorie = odbc_result($kategorie, 1);
}
echo &quot;<option>$kategorie</option>&quot;;
echo &quot;</select>&quot;;

box2:

echo &quot;<select size=1 name=subkat>&quot;;

while (odbc_fetch_row($subkategorie);
{
$kategorie = odbc_result($subkategorie, 1);
}
echo &quot;<option>$subkategorie</option>&quot;;
echo &quot;</select>&quot;;

 
Hi sleipnir214

This is not what i wont to do.
Because the User must know the Result of Box 1 to select a subcategory in box 2

He can change the value in box1 and see then the associated subcategories in box2 dynamicly

 
that's also possible, you submit to the same page. and make that the option selected in the first box becomes selected.

Code:
echo &quot;<option>$subkategorie&quot;; 
if ($subkategorie==$kat) {echo &quot; SELECTED &quot;;}
echo &quot;</option>&quot;;


you either submit the value to the same page and make a reload of that page or you put it in a frame structure where box1 is in the upper frame and after change the bottom frame is loaded with the appropiate $KAT filter
 
and not to forget the source code of that page

Code:
$query=&quot;SELECT botid,botdescr FROM bottlertable ORDER BY botdescr&quot;;
$rsbot=mysql_query($query,$conn);

headsectie(&quot;The Whiskydatabase&quot;); //forget this code, it's a standard html header !//

?>
<form name=&quot;tektips&quot; action=&quot;whlist.php3&quot; target=&quot;main&quot; method=post>

<TR><TD><P>Bottler</P></TD><TD><select name=&quot;whbotid&quot; onchange=&quot;window.location.replace('example1.php3?whbotid='+ window.document.tektips.whbotid.value)&quot;><option value=&quot;&quot;>Empty
<? 
$i=0;
$list = mysql_num_rows($rsbot); 
while($i < $list)	{
$row = mysql_fetch_array($rsbot); 
$botid=$row[&quot;botid&quot;];
$botdescr=$row[&quot;botdescr&quot;];

   echo &quot;<option value='$botid'&quot;;
if ($botid==$whbotid) {echo &quot; SELECTED &quot;;}


   echo &quot;>$botdescr&quot;;
$i++;
}
?>

</select></TD><td></td></TR>

<tr><td><p>Whisky</P></TD><td><select name=&quot;whname&quot;><option value=&quot;&quot;>Empty
<? 
$query=&quot;SELECT distinct(whname),whbotid FROM whiskytable where whbotid='$whbotid' order by whname&quot;;
$rs=mysql_query($query,$conn);

$i=0;
$list = mysql_num_rows($rs); 
while($i < $list)	{
$row = mysql_fetch_array($rs); 
$whname=$row[&quot;whname&quot;];
   echo &quot;<option value='$whname'>$whname&quot;;
$i++;
}
?>
</select></TD><td><? echo $query.&quot;<br>number of records &quot;.$list;?></td></TR>
 
Hi hos2

Thanks for your Time and this good example
That was what im looking for

great

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top