Adding options to select on a PocketPC

Discussion in 'Javascript' started by Robin Johnson, Jun 22, 2004.

  1. 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.
    Robin Johnson, Jun 22, 2004
    1. Advertisements

  2. 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+).

    Thomas 'PointedEars' Lahn, Jun 29, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.