Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 08:17 PM
Felix Natter
Guest
 
Posts: n/a
Default multiple <select> + IE: selection invisible

hi,

I have a php-Script which gets passed a Boat-ID and this is used to
mark an element in a <select> as the default:
<select name="boote[]" multiple="multiple" size="5">
<option value='43'>Aisha</option>
<option value='40'>Amsterdam</option>
<option value='55'>Asmaa</option>
<option value='20'>Beau Rivage</option>
<option value='48'>Blue Perl</option>
<option value='49'>Blue Planet 1</option>
<option value='37'>Capt. Moro</option>
<option value='41'>Coral Queen</option>
<option value='2' selected='selected'>Diamond-Heaven</option>
<option value='10'>Discovery</option>
<option value='21'>Dive One</option>
</select>

The problem is that this is a multiple selection <select> and while
with the above code, "Diamond-Heaven" is selected, it is
not visible (not in the scrolled window).

How can I make it behave somewhat like Mozilla (selected item is in
visible window by default)?

Maybe using javascript?

thanks,

--
Felix Natter
  #2  
Old July 20th, 2005, 08:17 PM
Harlan Messinger
Guest
 
Posts: n/a
Default Re: multiple <select> + IE: selection invisible


"Felix Natter" <felix.natter@ldc.de> wrote in message
news:m3zn6atwig.fsf@werkstatt4.ldc...[color=blue]
> hi,
>
> I have a php-Script which gets passed a Boat-ID and this is used to
> mark an element in a <select> as the default:
> <select name="boote[]" multiple="multiple" size="5">
> <option value='43'>Aisha</option>
> <option value='40'>Amsterdam</option>
> <option value='55'>Asmaa</option>
> <option value='20'>Beau Rivage</option>
> <option value='48'>Blue Perl</option>
> <option value='49'>Blue Planet 1</option>
> <option value='37'>Capt. Moro</option>
> <option value='41'>Coral Queen</option>
> <option value='2' selected='selected'>Diamond-Heaven</option>
> <option value='10'>Discovery</option>
> <option value='21'>Dive One</option>
> </select>
>
> The problem is that this is a multiple selection <select> and while
> with the above code, "Diamond-Heaven" is selected, it is
> not visible (not in the scrolled window).
>
> How can I make it behave somewhat like Mozilla (selected item is in
> visible window by default)?[/color]

If more than one item happens to be selected, how would you propose to
arrange for all of them to appear in the visible portion of the list at the
same time? The selected items might even include the first and last items in
the list. You can see from considering this that it's not practical for
multi-selection lists to behave in the manner you're used to from
single-selection lists.

  #3  
Old July 20th, 2005, 08:17 PM
Felix Natter
Guest
 
Posts: n/a
Default Re: multiple <select> + IE: selection invisible

"Harlan Messinger" <h.messinger@comcast.net> writes:
[color=blue]
> "Felix Natter" <felix.natter@ldc.de> wrote in message
> news:m3zn6atwig.fsf@werkstatt4.ldc...[color=green]
>> hi,
>>
>> I have a php-Script which gets passed a Boat-ID and this is used to
>> mark an element in a <select> as the default:
>> <select name="boote[]" multiple="multiple" size="5">
>> <option value='43'>Aisha</option>
>> <option value='40'>Amsterdam</option>
>> <option value='55'>Asmaa</option>
>> <option value='20'>Beau Rivage</option>
>> <option value='48'>Blue Perl</option>
>> <option value='49'>Blue Planet 1</option>
>> <option value='37'>Capt. Moro</option>
>> <option value='41'>Coral Queen</option>
>> <option value='2' selected='selected'>Diamond-Heaven</option>
>> <option value='10'>Discovery</option>
>> <option value='21'>Dive One</option>
>> </select>
>>
>> The problem is that this is a multiple selection <select> and while
>> with the above code, "Diamond-Heaven" is selected, it is
>> not visible (not in the scrolled window).
>>
>> How can I make it behave somewhat like Mozilla (selected item is in
>> visible window by default)?[/color]
>
> If more than one item happens to be selected, how would you propose to
> arrange for all of them to appear in the visible portion of the list at the
> same time? The selected items might even include the first and last items in
> the list. You can see from considering this that it's not practical for
> multi-selection lists to behave in the manner you're used to from
> single-selection lists.[/color]

It is practical for the special case that only one item is selected!
(even when two items are selected it can just jump to the first one,
but I need only the "one element" special case)

Consider: the code above appears in a php script query_boat.php which
accepts a parameter 'boat'. This parameter (value 2 in example above)
specifies which boat is pre-selected. Now the user is on the
description page for the boat "Diamond-Heaven" and clicks on the link
"send query for this boat" (query_boat.php?boat=2) => only one
selection!

Now the user will be confused if he/she does not find that
"Diamond-Heaven" is preselected. So maybe I could read the current
selection and scroll to the appropriate position using javascript?

thanks,

--
Felix Natter
  #4  
Old July 20th, 2005, 08:17 PM
Pierre Goiffon
Guest
 
Posts: n/a
Default Re: multiple <select> + IE: selection invisible

"Felix Natter" <felix.natter@ldc.de> a écrit dans le message de
news:m3zn6atwig.fsf@werkstatt4.ldc[color=blue]
> I have a php-Script which gets passed a Boat-ID and this is used to
> mark an element in a <select> as the default:
> <select name="boote[]" multiple="multiple" size="5">
> <option value='43'>Aisha</option>
> <option value='40'>Amsterdam</option>
> <option value='55'>Asmaa</option>
> <option value='20'>Beau Rivage</option>
> <option value='48'>Blue Perl</option>
> <option value='49'>Blue Planet 1</option>
> <option value='37'>Capt. Moro</option>
> <option value='41'>Coral Queen</option>
> <option value='2' selected='selected'>Diamond-Heaven</option>
> <option value='10'>Discovery</option>
> <option value='21'>Dive One</option>
> </select>
>
> The problem is that this is a multiple selection <select> and while
> with the above code, "Diamond-Heaven" is selected, it is
> not visible (not in the scrolled window).
>
> How can I make it behave somewhat like Mozilla (selected item is in
> visible window by default)?[/color]

If the order of the option elements are not important, maybe your PHP script
could send the selected elements first ? Something like :

<select name="boote[]" multiple="multiple" size="5">
<option value='2' selected='selected'>Diamond-Heaven</option>
<option value='43'>Aisha</option>
<option value='40'>Amsterdam</option>
<option value='55'>Asmaa</option>
<option value='20'>Beau Rivage</option>
<option value='48'>Blue Perl</option>
<option value='49'>Blue Planet 1</option>
<option value='37'>Capt. Moro</option>
<option value='41'>Coral Queen</option>
<option value='10'>Discovery</option>
<option value='21'>Dive One</option>
</select>

  #5  
Old July 20th, 2005, 08:17 PM
Warden Dave
Guest
 
Posts: n/a
Default Re: multiple <select> + IE: selection invisible

"Felix Natter" <felix.natter@ldc.de> wrote:

[ SELECT ][color=blue]
> Now the user will be confused if he/she does not find that
> "Diamond-Heaven" is preselected. So maybe I could read the current
> selection and scroll to the appropriate position using javascript?[/color]

You could try something simple like +-:

onload = function() {
var SelectObject = document.formName.elements["boote[]"];
SelectObject.selectedIndex = SelectObject.selectedIndex;
}


WD


  #6  
Old July 20th, 2005, 08:17 PM
Felix Natter
Guest
 
Posts: n/a
Default Re: multiple <select> + IE: selection invisible

"Pierre Goiffon" <pgoiffon@nowhere.invalid> writes:
[color=blue]
> "Felix Natter" <felix.natter@ldc.de> a écrit dans le message de
> news:m3zn6atwig.fsf@werkstatt4.ldc[color=green]
>> I have a php-Script which gets passed a Boat-ID and this is used to
>> mark an element in a <select> as the default:
>> <select name="boote[]" multiple="multiple" size="5">
>> <option value='43'>Aisha</option>
>> <option value='40'>Amsterdam</option>
>> <option value='55'>Asmaa</option>
>> <option value='20'>Beau Rivage</option>
>> <option value='48'>Blue Perl</option>
>> <option value='49'>Blue Planet 1</option>
>> <option value='37'>Capt. Moro</option>
>> <option value='41'>Coral Queen</option>
>> <option value='2' selected='selected'>Diamond-Heaven</option>
>> <option value='10'>Discovery</option>
>> <option value='21'>Dive One</option>
>> </select>
>>
>> The problem is that this is a multiple selection <select> and while
>> with the above code, "Diamond-Heaven" is selected, it is
>> not visible (not in the scrolled window).
>>
>> How can I make it behave somewhat like Mozilla (selected item is in
>> visible window by default)?[/color]
>
> If the order of the option elements are not important, maybe your PHP script
> could send the selected elements first ? Something like :
>
> <select name="boote[]" multiple="multiple" size="5">
> <option value='2' selected='selected'>Diamond-Heaven</option>
> <option value='43'>Aisha</option>
> <option value='40'>Amsterdam</option>
> <option value='55'>Asmaa</option>
> <option value='20'>Beau Rivage</option>
> <option value='48'>Blue Perl</option>
> <option value='49'>Blue Planet 1</option>
> <option value='37'>Capt. Moro</option>
> <option value='41'>Coral Queen</option>
> <option value='10'>Discovery</option>
> <option value='21'>Dive One</option>
> </select>[/color]

Thanks! I came to that conclusion as well. The order is alphabetic,
but I will just move the selected items to the top (maybe with
a "-----" separator).

--
Felix Natter
  #7  
Old July 20th, 2005, 08:17 PM
Felix Natter
Guest
 
Posts: n/a
Default Re: multiple <select> + IE: selection invisible

"Warden Dave" <warden_dave@web.de> writes:
[color=blue]
> "Felix Natter" <felix.natter@ldc.de> wrote:
>
> [ SELECT ][color=green]
>> Now the user will be confused if he/she does not find that
>> "Diamond-Heaven" is preselected. So maybe I could read the current
>> selection and scroll to the appropriate position using javascript?[/color]
>
> You could try something simple like +-:
>
> onload = function() {
> var SelectObject = document.formName.elements["boote[]"];
> SelectObject.selectedIndex = SelectObject.selectedIndex;
> }[/color]

this works, thanks! well, almost: if multiple items are selected
(which may happen the second time the page is loaded i.e. when the
user selects another item via Ctrl-click and submits but the form does
not validate) then selectedIndex only returns the first Index and so
all other selections will get lost.

Is there a way (must be compatible with as many browsers as possible)
to get the indices of *all* selected items? If there's no clean solution
I can just use the solution proposed by Pierre Goiffon in this thread.

thanks a lot,

--
Felix Natter
  #8  
Old July 20th, 2005, 08:17 PM
Warden Dave
Guest
 
Posts: n/a
Default Re: multiple <select> + IE: selection invisible

"Felix Natter" <felix.natter@ldc.de> wrote:[color=blue]
> "Warden Dave" <warden_dave@web.de> writes:[/color]
[color=blue][color=green]
>> You could try something simple like +-:
>>
>> onload = function() {
>> var SelectObject = document.formName.elements["boote[]"];
>> SelectObject.selectedIndex = SelectObject.selectedIndex;
>> }[/color][/color]
[color=blue]
> this works, thanks! well, almost: if multiple items are selected
> (which may happen the second time the page is loaded i.e. when the
> user selects another item via Ctrl-click and submits but the form does
> not validate) then selectedIndex only returns the first Index and so
> all other selections will get lost.[/color]

In that case... try something else ;), e.g.:

onload = function() {
var SelectObject = document.theForm.elements["boote[]"];
for (var i=SelectObject.options.length-1; i>=0; i--)
SelectObject.options[i].selected = SelectObject.options[i].selected;
}


WD


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles