Re: Retaining listbox selections

From: Date: Fri, 20 Dec 2013 23:08:19 +0000
Subject: Re: Retaining listbox selections
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-322589@lists.php.net to get a copy of this message
On Fri, 2013-12-20 at 18:03 -0500, Larry Martell wrote: > I have a listbox and when the user selects items they are highlighted. Then > I process the form and when I generate the next web page (which has the > listbox) I want the selected items still to be highlighted. Can I do this > from PHP when I generate the listbox or must that be done client side from > javascript? Yes, it's pretty easy, here's an example: <select name="colour"> <?php $colours = array('red','blue','green','yellow'); foreach($colours as $colour) { $selected = (isset($_POST['colour']) && $colour == $_POST['colour'])?'selected="selected"':''; echo "<option value=\"$colour\" $selected>$colour</option>"; } ?> </select> -- Thanks, Ash http://www.ashleysheridan.co.uk

« previous php.general (#322589) next »