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

How to keep selected values in select field?!?

P: n/a
I want to keep selected values in select list when i click on another
option...with a click on a mouse...

if i have 3 options in select list and i click first option..it gets
selected..if i then click on third option ..it gets selected but i want
also the first option to stay selected

when i click on option that is already selected, then it should be
deselected

if i double click on option...than only this option should be selected

so........

I tried to use onChange and onClick events on select field..the problem
is that in onChange event i get selectedIndex that represents and
option that i have just clicked (i can't get previously selected
options)..

in onClick event i cannot even get the options i just selected, just
previously selected..

so i was thinking to combine this two events to get all selection,
previosly selected and option taht i selected last

the proble is that when i fill array with an options that was previosly
selected and i want to use this array in onClick event, the array is
undefined...

so heres my problem...if anyone knows how to solve it or just give me
some advice , i'll be very happy :)

thx and bye

Oct 11 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
sm*******@gmail.com wrote:
I want to keep selected values in select list when i click on another
option...with a click on a mouse...

if i have 3 options in select list and i click first option..it gets
selected..if i then click on third option ..it gets selected but i want
also the first option to stay selected

when i click on option that is already selected, then it should be
deselected

if i double click on option...than only this option should be selected

so........

I tried to use onChange and onClick events on select field..the problem
is that in onChange event i get selectedIndex that represents and
option that i have just clicked (i can't get previously selected
options)..

in onClick event i cannot even get the options i just selected, just
previously selected..

so i was thinking to combine this two events to get all selection,
previosly selected and option taht i selected last

the proble is that when i fill array with an options that was previosly
selected and i want to use this array in onClick event, the array is
undefined...

so heres my problem...if anyone knows how to solve it or just give me
some advice , i'll be very happy :)

thx and bye

Hi,

Use the keyword multiple in your select

<select name="food" multiple>
<option value="1">banana
<option value="2">apple
<option value="3">pear
</select>

If you want to find out which options are selected at a certain moment, do
not use selectedIndex, it only works good for single-option slectbox.
In that case just loop over all option and check the 'selected' property by
hand.

Hope that helps.

Good luck!
Regards,
Erwin Moller
Oct 11 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.