keepAway Posted June 6, 2011 Share Posted June 6, 2011 $toateLigile = array("Promotie Sud", "Promotie Nord", "Onoare Sud", "Onoare Nord", "Divizia D", "Divizia C1", "Divizia C2", "Divizia C3", "Divizia C4", "Divizia C5", "Divizia C6", "Divizia C7", "Divizia B1", "Divizia B2", "Divizia A"); echo "<select name='toateLigile'>"; echo "<option value=''> ############ </option>"; for ($i=0; $i<=14; $i++) echo "<option value='".$toateLigile[$i]."'>".$toateLigile[$i]."</option>"; echo "</select>"; How do i make this piece of code stay selected at the previouse option after i send the input and the page is refreshed. Quote Link to comment https://forums.phpfreaks.com/topic/238515-question-about-html-select/ Share on other sites More sharing options...
xyph Posted June 6, 2011 Share Posted June 6, 2011 <?php $vals = array('a','b','c','d'); echo '<form method="post" action="#"><select name="select">'; foreach( $vals as $val ) { echo '<option value="'.$val.'"'; echo isset($_POST['select']) && $val == $_POST['select'] ? ' selected' : ''; echo '>'.$val.'</option>'; } echo '</select><input type="submit"></form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/238515-question-about-html-select/#findComment-1225694 Share on other sites More sharing options...
keepAway Posted June 6, 2011 Author Share Posted June 6, 2011 thx xyph Quote Link to comment https://forums.phpfreaks.com/topic/238515-question-about-html-select/#findComment-1225698 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.