Janwillem Borleffs wrote:
GIMME wrote: How do you tell if a drop down has been placed on a page?
In this instance I have a form named aForm and I'm checking
for a dropdown named div_list .
Use the `type` property:
document.aForm.div_list.type
It's value is either select-one or select-multiple (the latter for a
multiple select object).
When you want to know the number of defined options, use:
document.aForm.div_list.options.length
In fact he wanted to know if there is a "select" element in the
document. Your code can be useful but it will fail if there is
no "document", "document.aForm" or "document.aForm.div_list".
So as Lasse wrote, you first need to test if the parents of the
object and the object itself exist before you can check its "type"
property. And even then you may trigger a script error as there
may be no "type" property or reading it is forbidden (e.g. due to
missing ECMAScript conformance of the UA's script engine). You can
(and should) test for the former, however you can't test for the
latter because the test itself triggers the error and you cannot
catch it. Same goes for options.length.
PointedEars