469,275 Members | 1,717 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Adding options to select on a PocketPC

Hello,

I'm writing some dynamic forms code for running on a PocketPC (running Windows
2003). There is to be a set of select menus, and choosing a particular option
in one menu changes the options available in the next.

In an ordinary select element I can change the text and value of the various
options using

document.forms['myform'].elements.myselect.options[i].text = 'foo'
document.forms['myform'].elements.myselect.options[i].value = 'foo_value'

but I can't change the length of the options array: options.length doesn't
seem to accept assignment or the ++ operator (as I'm used to using for IE6 on
a desktop machine), or the method add(). If I can't add (and remove) options
I'll have to resort to a static number of options in the select, and just
blank out the ones I don't want, which I can do but is a bit unmannerly. I'd
appreciate it if anyone can help.

--
Robin Johnson
http://www.robinjohnson.f9.co.uk - rj@[no-spam]robinjohnson.f9.co.uk
"The labours of men of genius, however erroneously directed, scarcely ever fail
in contributing ultimately to the solid advantage of mankind." - Mary Shelley
Jul 23 '05 #1
1 1116
Robin Johnson wrote:
In an ordinary select element I can change the text and value of the various
options using

document.forms['myform'].elements.myselect.options[i].text = 'foo'
document.forms['myform'].elements.myselect.options[i].value = 'foo_value'

but I can't change the length of the options array: options.length doesn't
seem to accept assignment or the ++ operator (as I'm used to using for IE6 on
a desktop machine), or the method add().


var o = document.forms['myform'].elements['myselect'].options;
o[o.length] = new Option("text", "value");

works in all browsers (that implement DOM Level 0 as of NS/IE 3+).
PointedEars
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by David | last post: by
1 post views Thread by The Eclectic Electric | last post: by
1 post views Thread by Josh C. | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.