Jump to content

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

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.