473,574 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.option s;
if (!div_list) {}

fails as does

if ( null == typeof(document .aForm.div_list .options )
Thanks.
Jul 20 '05 #1
3 1244
gi************* ******@yahoo.co m (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.option s;
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.option s;
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/rasterTriangleD OM.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.option s.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.option s.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
8271
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 dropdown lists. If you change the selection of the left one (e.g. choose parentoption2), it should open up page2.htm in a popup window.
1
2933
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 javascript; I just don't get the syntax at all. If anyone could help, I would appreciate it. I'm probably pretty close. Please note that because it's an...
1
1360
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 box(dropdown list). How would I do this in C#? It seems like it should be real easy but I can't make it work. Thanks in advance
6
10670
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. Let's say you select 1 of the items, and are properly redirected. You press the back button. I have three servers providing two different...
3
4418
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 the second is populated based on the input in the first. The first dropdown is inside a "If Not Page.IsPostBackThey" if loop. Both have autopostback...
5
2581
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 = "Any unsaved data will be lost."; } </SCRIPT> <BODY onbeforeunload="closeIt()">
4
4567
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 reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The...
2
2151
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: Under specific conditions, I have noticed a problem in IE7 with a popular dropdown method. In IE7, the dropdown fails to spring back up if you...
5
10328
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 I would like to add a checkbox or dropdown control to the .RLDC and have Item #1, Item #2, or Item #3 display conditionally based on a checkbox being...
0
7803
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8044
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5618
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5299
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2240
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1337
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1056
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.