Jump to content

question about HTML Select


keepAway

Recommended Posts

   
$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.

 

Link to comment
https://forums.phpfreaks.com/topic/238515-question-about-html-select/
Share on other sites

<?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>';

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.