SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript drop down menu with descriptions

    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:

    Code:
    	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>
    	");

  2. #2
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,692
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Try changing
    > if (document.getElementById)
    to
    > if (document.getElementById())
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •