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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating DD box from array

Status
Not open for further replies.

nemini

Programmer
Sep 22, 2008
21
US
Not feeling too bright!
it has to be obvious but...
I am trying as per the code example to populate a DD box from an array
the box picks up the correct number but each value reads "array" instead of the array value
Code:
if ($quantity==1) { $q=array(1=>"1"); };
if ($quantity==2) { $q=array(1=>"1", 2=>"2"); }; 
if ($quantity==3) { $q=array(1=>"1", 2=>"2", 3=>'3'); }; 
	echo"<form><select name='quantity' onchange='pass_val(this.value)'>";
	echo"<option value=''>Select a number";
	foreach($q as $key => $value)
	{
	echo"<option value=$q>$q";
 	echo'</option>';
	}
	echo"</select></form><div id=\"show\"></div></td></tr>
";
Thanks
 
Of course because q is an array. You want the values stored in the array so:

Code:
 foreach($q as $key => $value)
    {
    echo"<option value=[red]$value[/red]>[red]$value[/red]";
     echo'</option>';
    }



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
vacunita, Thank you, yes you are indeed correct!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top