By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,971 Members | 900 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,971 IT Pros & Developers. It's quick & easy.

multiple <select> + IE: selection invisible

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

"Felix Natter" <fe**********@ldc.de> wrote in message
news:m3************@werkstatt4.ldc...
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)?


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.

Jul 20 '05 #2

P: n/a
"Harlan Messinger" <h.*********@comcast.net> writes:
"Felix Natter" <fe**********@ldc.de> wrote in message
news:m3************@werkstatt4.ldc...
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)?


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.


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
Jul 20 '05 #3

P: n/a
"Felix Natter" <fe**********@ldc.de> a écrit dans le message de
news:m3************@werkstatt4.ldc
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)?


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>

Jul 20 '05 #4

P: n/a
"Felix Natter" <fe**********@ldc.de> wrote:

[ SELECT ]
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?


You could try something simple like +-:

onload = function() {
var SelectObject = document.formName.elements["boote[]"];
SelectObject.selectedIndex = SelectObject.selectedIndex;
}
WD
Jul 20 '05 #5

P: n/a
"Pierre Goiffon" <pg******@nowhere.invalid> writes:
"Felix Natter" <fe**********@ldc.de> a écrit dans le message de
news:m3************@werkstatt4.ldc
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)?


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>


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
Jul 20 '05 #6

P: n/a
"Warden Dave" <wa*********@web.de> writes:
"Felix Natter" <fe**********@ldc.de> wrote:

[ SELECT ]
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?


You could try something simple like +-:

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


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
Jul 20 '05 #7

P: n/a
"Felix Natter" <fe**********@ldc.de> wrote:
"Warden Dave" <wa*********@web.de> writes:
You could try something simple like +-:

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

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.


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
Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.