468,541 Members | 1,820 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,541 developers. It's quick & easy.

Please SELECT question

How can I dynamically delete option from select object?

I know to add:

al.option[0] = new Option('x','y');

but what about delete all or some?

Thx in advance.

--
Fabri
-Mandrake "A Poma', c'hai 'na faccia...!"
-Pomata "Sì, se ce n'avevo due già stavo all'università... sotto
spirito!"
Jul 23 '05 #1
3 1312
Ivo
"Fabri" wrote
How can I dynamically delete option from select object?

I know to add:

al.option[0] = new Option('x','y');

but what about delete all or some?


Set the option to null:

al.option[0] = null;

This will immediately update the indeces of any following options and the
length of the collection. Watch out for that when deleting options in a
loop.

hth
ivo
Jul 23 '05 #2

Yes, as Ivo said, set it to null, as for if looping through the options[]
collection, loop from the bottom to top, otherwise, your top-bottom
indexing will be off on each iteration as the new iteration is going over
a newly-updated collection of indexes.

Danny

On Fri, 08 Jul 2005 08:11:10 -0700, Fabri <no@sp.am> wrote:
How can I dynamically delete option from select object?

I know to add:

al.option[0] = new Option('x','y');

but what about delete all or some?

Thx in advance.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #3
Danny wrote:

Yes, as Ivo said, set it to null, as for if looping through the
options[] collection, loop from the bottom to top, otherwise, your
top-bottom indexing will be off on each iteration as the new iteration
is going over a newly-updated collection of indexes.


If you want to remove the last 'x' number of options, change the
length of the selects' options collection:

select.options.length = select.options.length - x
--
Rob
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by A. Wiebenga | last post: by
4 posts views Thread by Orion | last post: by
2 posts views Thread by cpptutor2000 | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.