Getting a select statement after $_POST to retain value?

Afternoon,

I have a foreach loop and within that loop is a select box. Now I want to say if the value of the posted selected value ($_POST[‘for_title’]) is what has been selected then make it ‘selected’ – ie hold the value.


  $html = '<select name="for_title" class="inputbox">' . "\
"; 
  foreach ($options as $key=>$value) {
    $html .= '<option value="'.$key.''; 
	if ($_POST['for_title'] == $key ) { $html .=' selected'; }
	$html .= '">'.$value.'</option>' . "\
"; 	
  }
  $html .= "</select>

here’s my code, any idea as i’s not working?

Thanks

Additions in blue, removed in red:


  $html = '<select name="for_title" class="inputbox">' . "\
"; 
  foreach ($options as $key=>$value) {
    $html .= '<option value="'.$key.'[COLOR="Blue"]"[/COLOR]'; 
	if ($_POST['for_title'] == $key ) { $html .=' [COLOR="Blue"]selected="[/COLOR]selected[COLOR="Blue"]"[/COLOR]'; }
	$html .= '[COLOR="Red"]"[/COLOR]>'.$value.'</option>' . "\
"; 	
  }
  $html .= "</select>[COLOR="Blue"]";[/COLOR]

:slight_smile:

Magic - knew I wasn’t far away so thanks for that!