How to keep selected values in select field?!?

S

smash2004

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
 
E

Erwin Moller

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top