rs131
07-26-2006, 11:29 PM
Hello I am making an online text-based kinda game, and I am trying to get a script working that'll display the description of different kinds of drinks a person can buy (which are stored in the database) underneath a drop down box with allt he names of the drinks. Basically I had to use PHP because I needed to set the descriptions of each drink from the database using PHP into the javascript desc array. When I look at the error log on firefox it says that getElementById(container) has no properties. I do not understand javascript at all, and definiately don't know how to use it properly through PHP:
echo("<form name=\"drinks\"><select name=\"select_drinks\" size=\"1\"
onChange=\"javascript: displaydesc(document.drinks.select_drinks, desc, 'container');\">");
// Puts all drinks into a drop down menu
for($i = 1; $i <= $count; $i++)
{
echo("<option value=\"".$drink_id[$i]."\">".$name[$i]."</option>");
}
echo("hh");
echo("ggg");
echo("<span style=\"font-family: verdana; color: #FFFFFF;\" id=\"container\">gfh65htyyhd</span>hbgh");
echo("
<script type=\"text/javascript\"><!-- Begin");
echo("
");
echo("var desc = new Array();");
echo("
");
// Puts all descriptions into a javascript array
for($i = 1; $i <= $count; $i++)
{
echo("desc[".$i."]=\"".$description[$i]."\";
");
}
echo("function displaydesc(which, descriptionarray, container)
{
if (document.getElementById)
document.getElementById(container).innerHTML=descriptionarray[which.selectedIndex];
}
");
echo("displaydesc(document.drinks.select_drinks, desc, 'container');
");
echo("// End -->
</script>
");
echo("<form name=\"drinks\"><select name=\"select_drinks\" size=\"1\"
onChange=\"javascript: displaydesc(document.drinks.select_drinks, desc, 'container');\">");
// Puts all drinks into a drop down menu
for($i = 1; $i <= $count; $i++)
{
echo("<option value=\"".$drink_id[$i]."\">".$name[$i]."</option>");
}
echo("hh");
echo("ggg");
echo("<span style=\"font-family: verdana; color: #FFFFFF;\" id=\"container\">gfh65htyyhd</span>hbgh");
echo("
<script type=\"text/javascript\"><!-- Begin");
echo("
");
echo("var desc = new Array();");
echo("
");
// Puts all descriptions into a javascript array
for($i = 1; $i <= $count; $i++)
{
echo("desc[".$i."]=\"".$description[$i]."\";
");
}
echo("function displaydesc(which, descriptionarray, container)
{
if (document.getElementById)
document.getElementById(container).innerHTML=descriptionarray[which.selectedIndex];
}
");
echo("displaydesc(document.drinks.select_drinks, desc, 'container');
");
echo("// End -->
</script>
");