By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,843 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,843 IT Pros & Developers. It's quick & easy.

Checking existence of an object

P: n/a
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?
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <a7**************************@posting.google.com >,
pa**@wubios.wustl.edu enlightened us with...
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.
<snip> How do I test for the "object has no properties" error?

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.formname.radioname.length; i++)
{
if (document.formname.radioname[i].checked)
{
isChecked=true;
}
}

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

--
--
~kaeli~
Can you be a closet claustrophobic?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.