astralaaron Posted April 9, 2012 Share Posted April 9, 2012 This is not a big problem but just something that is kind of annoying because I have to write the options twice just to select the correct option when the page loads. So I was just wondering, how does everyone else handle this? <select name="selectTeamType"><?php$Y = $data['teamType'];$options = '<option value="0">select one</option>';$options .= ($Y == 1) ? '<option selected="selected" value="1">Soccer</option>' : '<option value="1">Soccer</option>';$options .= ($Y == 2) ? '<option selected="selected" value="2">Football</option>' : '<option value="2">Football</option>';$options .= ($Y == 3) ? '<option selected="selected" value="3">Baseball</option>' : '<option value="3">Baseball</option>';$options .= ($Y == 4) ? '<option selected="selected" value="4">Rugby</option>' : '<option value="4">Rugby</option>';echo($options);?></select> Link to comment Share on other sites More sharing options...
justsomeguy Posted April 9, 2012 Share Posted April 9, 2012 $options .= '<option value="1"' . ($Y == 1 ? ' selected="selected"' : '') . '>Soccer</option>'; Link to comment Share on other sites More sharing options...
astralaaron Posted April 9, 2012 Author Share Posted April 9, 2012 $options .= '<option value="1"' . ($Y == 1 ? ' selected="selected"' : '') . '>Soccer</option>'; I knew you would have a trick up your sleeve Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.