422,577 Members | 826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,577 IT Pros & Developers. It's quick & easy.

Please SELECT question

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a

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

P: n/a
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.