473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How to tell if a dropdown is defined on page

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 .
var div_list document.aForm.div_list.options;
if (!div_list) {}

fails as does

if ( null == typeof(document.aForm.div_list.options )
Thanks.
Jul 20 '05 #1
3 1238
gi*******************@yahoo.com (GIMME) writes:
How do you tell if a drop down has been placed on a page?
I assume you mean a select element. There are many ways,
depending on what you know about it.
In this instance I have a form named aForm and I'm checking
for a dropdown named div_list .
Much simpler, you know the name of the form and the select.
var div_list document.aForm.div_list.options;
Use
var div_lust = document.formes['aForm'].elements['div_list'];
This will be undefined if the element with name div_list isn't there.
Trying to get the options property will give an error if the select
element isn't there, so only do that after you have tested that it
exists.
if (!div_list) {}
div_list = div_list.options;
fails as does

if ( null == typeof(document.aForm.div_list.options )


Yes, you still try to find the options property of the undefined value.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
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
JW

Jul 20 '05 #3
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
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
1
by: Lance | last post by:
I am trying to select the item in the dropdown list the matches a value pulled from the database and set this matching item's selected property to true so that it is the selected item in the combo...
6
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy. ...
3
by: devNorway | last post by:
I have been struggling with a problem for days now, and searched for related problems and solutions but had no luck. I have two dropdown listboxes where the first is populated in page load and...
5
by: nic829 | last post by:
I am trying to write a code such that when user close the browser or netvigate to other page, a message box will show up. <SCRIPT> function closeIt() { event.returnValue =...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
2
by: dorayme | last post by:
After posting similar in another forum a few hours ago, it strikes me I should have subscribed to this group and included it here. There may be a simple js tweak that someone knows or can think of:...
5
by: =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== | last post by:
I have a VS 2008 ASP.NET webform that has a reportview tag on it, accessing an .RLDC report in local report. The columns for the report are essentially: Month Item #1 Item#2 Item#3 ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.