I figured it'd be more useful if I cleaned up your code a little to show you what I mean. I haven't tested this at all -- it's all your original code with a couple comments added and some output formatting changes/fixes (added indentation and newlines to output).
<?php
// firsttry2.php
// attempting dynamic listboxes
include "include/open_db.inc";
include "include/common_db.inc";
$sql = "SELECT DISTINCT printed FROM media";
$result = mysql_query($sql, $db);
$rows = mysql_num_rows($result);
$sql1 = "SELECT DISTINCT size FROM media";
$result1 = mysql_query($sql1, $db);
$rows1 = mysql_num_rows($result1);
for($i=0;$i<$rows1;$i++)
{
$arrItems1[] = mysql_fetch_array($result1);
$arrItemsGrp1[] = $i;
}
$sql2 = "SELECT DISTINCT weight, finish FROM media WHERE printed='$firstChoice' AND size='$secondChoice'";
$result2 = mysql_query($sql2, $db);
$rows2 = mysql_num_rows($result2);
for($i=0;$i<$rows2;$i++)
{
$arrItems2[] = mysql_fetch_array($result2);
$arrItemsGrp2[] = $i;
}
// This is a simple utility function that appends a newline character to a
// string before outputting it.
function echol($str = "")
{
echo "{$str}\n";
}
echol("<html>");
ehcol("<head>");
echol("<title>Populate List Box</title>");
echol("<script>");
echol("function selectChange(control, controlToPopulate, ItemArray, GroupArray)");
echol("{");
echol(" var myEle;");
echol(" var x;");
// Empty the second drop down box of any choices
echol(" for(var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;");
echol(" if(control.name==\"firstChoice\") {");
// Empty the third drop down box of any choices
echol(" for (var q=myChoices.thirdChoice.options.length;q>=0;q--) myChoices.thirdChoice.options[q] = null;");
echol(" }");
// ADD Default Choice - in case there are no values
echol(" myEle = document.createElement(\"option\");");
echol(" myEle.value = 0;");
echol(" myEle.text = \"[SELECT]\";");
echol(" controlToPopulate.add(myEle);");
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
echol(" for (x=0;x<ItemArray.length;x++)");
echol(" {");
echol(" if(GroupArray[x]==control.value)");
echol(" {");
echol(" myEle=document.createElement(\"option\");");
echol(" myEle.value=x;");
echol(" myEle.text=ItemArray[x];");
echol(" controlToPopulate.add(myEle);");
echol(" }");
echol(" }");
echol("}");
/////////////////////////////////////////////////////
// GENERATE YOUR JAVASCRIPT ARRAY VARIABLES HERE. //
/////////////////////////////////////////////////////
// End -->
echol("</script>");
echol("</head>");
echol("<body>");
echol("<center>");
echol("<br /><br />");
echol("<form NAME='myChoices' METHOD='post' ACTION=''>");
echol(" <table WIDTH='600' BORDER='5' BORDERCOLOR='navy' BGCOLOR='#D7D7D7'>");
echol(" <select ID='firstChoice' NAME='firstChoice' ONCHANGE=\"selectChange(this, myChoices.secondChoice, arrItems1, arrItemsGrp1);\">");
echol(" <option VALUE=0 SELECTED>[SELECT]</option>");
for($i=1;$i<$rows+1;$i++)
{
$data = mysql_fetch_object($result);
echol(" <option value={$i}>{$data->printed}</OPTION>");
}
echol(" </select>");
echol(" <br/><br/>");
echol(" <select ID='secondChoice' NAME='secondChoice' ONCHANGE=\"selectChange(this, myChoices.thirdChoice, arrItems2, arrItemsGrp2);\">");
echol(" </select>");
echol(" <br /><br />");
echol(" <select ID='thirdChoice' NAME='thirdChoice'>");
echol(" </select>");
echol(" </table>");
echol("</form>");
echol("</center>");
echol("</body>");
echol("</html>");
mysql_free_result($result);
mysql_close($db);
?>
Take care,
Nik
http://www.bigaction.org/