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

Display just selected value in listbox???

Status
Not open for further replies.

zishan876

Programmer
Mar 19, 2007
61
US
Hi:
I have the following code which I inherited from a project I got assigned... I am trying to learn PHP along with this... So I have a listbox here that I just want to display the selected value and not the entire list... And this is read only so that the user can not change it or do anything to it...
Code:
   <select multiple size="10" name="preferred_locations[]">

  <?php
				$arrRegions = explode("\n", aParameter(802));
				
													
												
				//echo "<table width=100%>";

				foreach($arrRegions as $strRegion)
				{
				
					$arrCategoryItems = explode(".",$strRegion,2);
					
					if(strstr($arrCategoryItems[0],"."))
					{
						continue;
					}
					
					if($iCounter%2==0)
					{
						//echo "<tr height=24>\n";
					}
					 //echo "<td class=text>\n";
					 
					//echo "\n <option ".(in_array(trim($arrCategoryItems[1]), $arrSelectedLocations)?"selected":"")." value=\"".trim($arrCategoryItems[1])."\" name=\"preferred_locations[]\"> ".$arrCategoryItems[1]."</option>";
					  echo "\n <option ".(in_array(trim($arrCategoryItems[1]), $arrSelectedLocations)?"selected":"")." value=\"".trim($arrCategoryItems[1])."\" name=\"preferred_locations[]\"> ".$arrCategoryItems[1]."</option>";
					 
					//echo "\n <input disabled type=checkbox ".((is_array($arrSelectedLocations)&&in_array(trim($arrCategoryItems[1]), $arrSelectedLocations))?"checked":"")." value=\"".trim($arrCategoryItems[1])."\" name=\"preferred_locations[]\"> ".$arrCategoryItems[1];
					 //echo "</td>\n";
					
					if(($iCounter+1)%2==0)
					{
					 	//echo "</tr>\n";
					}
					$iCounter ++;
				}
				
				// echo "</table>";
				 
		?>
  
  </select>
Any help would be appreciated.. Thanks
 
After you submitted the form of which this <select> is part, the array preferred_locations[] will only contain the selected items.
Or am I missing the point of your question?
Elck
 
Well the list box has all the regions plus the selected ones highlighted... I was wondering if I can just display the hignlighted ones and not everything else... Maybe not a list box but just the answers the user chose...
<== this is the site I am trying to configure...
Thanks
Z
 
As elck said once you submit the form, the array will contain only those options that where selected. So you can echo them out as you please.

Try this:

Once the form is submitted try looking in $_POST['preferred_locations'] for the selected options. Provided your form uses the POST method.


----------------------------------
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top