Checking existence of an object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul THompson

    Checking existence of an object

    I am trying to see which of the elements of a
    a) select list have been selected.
    b) radio button have been checked.

    I have set up a for loop

    for (i=0;
    !document._xedx _._cdm[i].selected;
    i++) {}

    This works fine, and terminates when the selected object is found.

    How can I stop this if NO CHOICE has been selected? Then of course I
    keep incrementing i, and get

    f has no properties.

    after it gets too big.

    How do I test for the "object has no properties" error?
  • kaeli

    #2
    Re: Checking existence of an object

    In article <a7ef5268.03120 42148.3c4ab24b@ posting.google. com>,
    paul@wubios.wus tl.edu enlightened us with...[color=blue]
    > I am trying to see which of the elements of a
    > a) select list have been selected.
    > b) radio button have been checked.
    >
    > I have set up a for loop
    >
    > for (i=0;
    > !document._xedx _._cdm[i].selected;
    > i++) {}
    >
    > This works fine, and terminates when the selected object is found.
    >[/color]
    <snip>[color=blue]
    > How do I test for the "object has no properties" error?
    >[/color]


    You don't. You use the length property instead of just incrementing
    wildly. Use a boolean isChecked or something if you want to see if
    anything was checked/selected.

    For radios:
    var boolean isChecked = false;
    for (i=0; i<document.form name.radioname. length; i++)
    {
    if (document.formn ame.radioname[i].checked)
    {
    isChecked=true;
    }
    }

    For selects
    for (i=0; i<document.form name.selectname .options.length ; i++)
    {
    if (document.formn ame.selectname. options[i].selected)
    {
    isChecked=true;
    }
    }

    --
    --
    ~kaeli~
    Can you be a closet claustrophobic?



    Comment

    Working...