472,142 Members | 1,338 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

How to keep selected values in select field?!?

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
1 2655
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.

Similar topics

3 posts views Thread by Sarah West | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.