arnico Posted November 9, 2005 Report Share Posted November 9, 2005 Vienkārši paņem no PHP kuri/š optioni/s bij ieselektēti/s un tad vadot ārā optionu sarakstu ieselektētajam/iem pieliec klāt "selected" <option value="bla bla" selected> Link to comment Share on other sites More sharing options...
php_Stopp Posted November 9, 2005 Report Share Posted November 9, 2005 (edited) aa.. <select name="selectliste"><?php switch ($_POST['selectliste']) { case 'pirmais': echo "<option value=\"pirmais\" selected=\"selected\">variants 1</option>\n<option value=\"otrais\">variants 2</option>"; case 'otrais': echo "<option value=\"pirmais\">variants 1</option>\n<option value=\"otrais\" selected=\"selected\">variants 2</option>"; } ?></select> nu tas tā.. diezgan primitīvā rakstā.. Edited November 9, 2005 by php_Stopp Link to comment Share on other sites More sharing options...
arnico Posted November 9, 2005 Report Share Posted November 9, 2005 Tiešām diezgan primitīvi un vēl daudzkas optimizējams, bet doma aptuveni saprasta :) Link to comment Share on other sites More sharing options...
Ugabuga Posted November 9, 2005 Author Report Share Posted November 9, 2005 Kaut ko apmeeram liidziigu arii sashtukoju. Vnk, jo vairaak optioni, jo garaak tas sanaak.. Link to comment Share on other sites More sharing options...
php_Stopp Posted November 9, 2005 Report Share Posted November 9, 2005 (edited) var jau arī kaukā šitā..: <?php switch($_POST['selectliste']) { case 'pirmais': $1st_value = ' selected="selected"'; case 'otrais': $2nd_value = ' selected="selected"'; } ?> <select name="selectliste"> <option value="pirmais"<? echo (isset($1st_value) ? $1st_value : ''); ?>>1. variants</option> <option value="otrais"<? echo (isset($2nd_value) ? $2nd_value : ''); ?>>2. variants</option></select> tas ar tā, uz ātru roku.. Edited November 9, 2005 by php_Stopp Link to comment Share on other sites More sharing options...
v3rb0 Posted November 9, 2005 Report Share Posted November 9, 2005 vaij šitā $_POST['selectliste'] = (isset($_POST['selectliste']))?$_POST['selectliste']:false; $values = array( 'pirmais' => '1. variants', 'otrais' => '2. variants', 'daudzais' => 'n. variants' ); echo '<select>'; foreach($values as $value => $label) echo '<option value="'.$value.'"'.( ($_POST['selectliste'] == $value)?' selected="selected"':'').'>'.$label.'</option>'; echo '</select>'; Link to comment Share on other sites More sharing options...
php_Stopp Posted November 9, 2005 Report Share Posted November 9, 2005 nu jaa, v3rb0 variants visizdevīgākais.. nebija ienācis prātā ar arrayiem strādāt :P Link to comment Share on other sites More sharing options...
Ugabuga Posted November 10, 2005 Author Report Share Posted November 10, 2005 Danke.. Link to comment Share on other sites More sharing options...
Recommended Posts