Adding options to select on a PocketPC

R

Robin Johnson

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.text = 'foo'
document.forms['myform'].elements.myselect.options.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.
 
T

Thomas 'PointedEars' Lahn

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

document.forms['myform'].elements.myselect.options.text = 'foo'
document.forms['myform'].elements.myselect.options.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
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top