Try this
if (isset($_POST['taskOption'])) { $Option = $_POST['taskOption']; } while($hej < count($hejsan)) { if($hej==$_POST['taskOption']){ $selected = "selected=selected"; }else{ $selected = ""; } echo '<option value="' . $hej . '" '.$selected .'>' . $hejsan[$hej] . '</option>'; $hej++; }