Re: HTML SELECT Lists -- ??? -- SOLVED.
| From: | Jason Caldwell | Date: | Tue, 23 Oct 2001 21:21:24 +0000 |
| Subject: | Re: HTML SELECT Lists -- ??? -- SOLVED. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-71993@lists.php.net to get a copy of this message | ||
I wrote some code that will grab the selected items and place them at the
top of the list, then list below that all unselected items -- it actually
works pretty well and is (of course) browser independent.
If anyone is curious on how this is done -- I've put some sample code below
as an example:
<?
$states = array('ca'=>'California','nv'
=>'Navada','tx'=>'Texas','ri'=>'Rhode
Island,'co'=>'Colorado');
$mySelections = 'ca,tx,ri';
$selectedItems = explode(',', $mySelections);
/* This 1st FOREACH command builds the list showing only selected items
(at the top) */
foreach($states as $key=$value)
{
if(in_array($key, $selectedItems))
{
print('<option value="' . $key . '"' . selected
.'>' . $value);
print("\n");
}
}
/* This 2nd FOREACH command builds the list, omitting any SELECTED items
*/
foreach($states as $key=>$value)
{
/* If $key is in the array $selectedItems then CONTINUE the loop
here (skipping the print commands) */
if(in_array($key, $selectedItems))
continue;
print('<option value="' . $key . '">' . $value);
print("\n");
}
Thanks.
"Jason Caldwell" <jason@thinkingman.org> wrote in message
news:20011023172221.87136.qmail@pb1.pair.com...
> I have a (multiple selection) select list on my web page -- My pages are
> setup with Save & Go Back buttons (through sessions) -- in IE when I
select
> multiple items (or any item) then go forward to the next page, then go
> back -- the items are still selected, but the select list starts at the
> top -- hence, I have to scroll down to see my selected items... just
FYI --
> I'm building the select lists (and what selected) programmatically -- when
I
> say I "Go Back" -- I'm not using the browsers back button -- but instead
the
> form button I created for this purpose.
>
> Now -- interestingly, in NS6 -- when I go back the select list starts at
the
> *last* selected items, hence I am thrown into my selected choices -- this
is
> desirable.
>
> Is there a way with PHP I can make IE kinda do the same thing?
>
> Thanks
> Jason
>
>