473,545 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getElementByID error...

Hi all!

I have this annoying problem with netscape...
I'm trying to access a form value by using getElementByID and in NS i
end up with a null reference.

The following HTML is the form component that gives me headache:
<form name='task' ...>
....
<select name='priorityS elect' class='selectwi dth'>
<option value=''>Choose one</option>
<option value='1'>Criti cal</option>
<option value='2'>High</option>
<option value='3'>Mediu m</option>
<option value='4'>Low</option>
</select>
....
</form>

And the related javascript code:
if(document.get ElementById("pr ioritySelect"). disabled == false)
{ ... }

When digging into this I can get the desired information by using
document.task.p rioritySelect, but that should not be necessary, right?

I hope that anyone knows how to deal with this problem...

Regards,
Drew
Jul 20 '05 #1
8 2501
drew wrote:
Hi all!

I have this annoying problem with netscape...
I'm trying to access a form value by using getElementByID and in NS i
end up with a null reference.

The following HTML is the form component that gives me headache:
<form name='task' ...>
...
<select name='priorityS elect' class='selectwi dth'>


If you want to use getElementById( ) to access this element, then it needs an
id attribute:

<select id="..." ...>
--
Jim Dabell

Jul 20 '05 #2
"drew" <an*****@crossn et.se> wrote in message
news:49******** *************** ***@posting.goo gle.com...
I have this annoying problem with netscape...
I'm trying to access a form value by using getElementByID
and in NS i end up with a null reference.

The following HTML is the form component that gives me headache:
<form name='task' ...>
...
<select name='priorityS elect' class='selectwi dth'>
This element has no ID attribute.

<snip>And the related javascript code:
if(document.ge tElementById("p rioritySelect") .disabled == false)
{ ... }
The above select element has no ID attribute so what makes you think
that a method with the name "getElementById " could retrieve a reference
to it?
When digging into this I can get the desired information
by using document.task.p rioritySelect,
Better would be:-

document.forms['task'].elements['prioritySelect ']

- as it conforms with the pertinent parts of the W3C HTML DOM
specification and is supported by every browser that understands what a
form is (for maximum back compatibility).
but that should not be necessary, right?
If you don't give an element an ID it is unrealistic to expect to be
able to refer to it by ID.
I hope that anyone knows how to deal with this problem...


Give the element an ID to refer to it by or use a property accessor
relative to the document.forms collection and the elements collection of
the form.

Richard.
Jul 20 '05 #3
On Thu, 15 Jan 2004 14:08:19 +0000, Jim Dabell
<ji********@jim dabell.com> wrote:
drew wrote:
Hi all!

I have this annoying problem with netscape...
I'm trying to access a form value by using getElementByID and in NS i
end up with a null reference.

The following HTML is the form component that gives me headache:
<form name='task' ...>
...
<select name='priorityS elect' class='selectwi dth'>


If you want to use getElementById( ) to access this element, then it needs an
id attribute:

<select id="..." ...>

That does seem the obvious comment...
Jul 20 '05 #4
On Thu, 15 Jan 2004 14:20:48 -0000, "Richard Cornford"
<Ri*****@litote s.demon.co.uk> wrote:
If you don't give an element an ID it is unrealistic to expect to be
able to refer to it by ID.


not in IE!

a=document.body .firstChild.uni queID;
el=document.get ElementById(a);
alert(el+','+el .id)

gEBI can get objects without ID's...

(this can actually be useful if you don't want to keep a reference to
the object to avoid DOM leaks, and are worried about people mutating
ID's on you...)

Jim.
--
comp.lang.javas cript FAQ - http://jibbering.com/faq/

Jul 20 '05 #5
"Jim Ley" <ji*@jibbering. com> wrote in message
news:40******** *******@news.ci s.dfn.de...
On Thu, 15 Jan 2004 14:20:48 -0000, "Richard Cornford"
<Ri*****@litot es.demon.co.uk> wrote:
If you don't give an element an ID it is unrealistic to
expect to be able to refer to it by ID.
not in IE!

a=document.bod y.firstChild.un iqueID;
el=document.ge tElementById(a) ;
alert(el+','+e l.id)


Was uniqueID introduced in IE 5.5 or 6? I was a bit alarmed to find that
all DOM elements also appear in the document.all collection under a
property name that corresponds to its uniqueID on IE 6. Particularly as
IE's property accessor resolution is slower the more properties an
object has and that would nearly double the size of the document.all
collection.
gEBI can get objects without ID's...

<snip>

Yes I have noticed, and it looks like gEBI is optimised on IE to look up
the ID in the document.all collection (returning the first element of
collections found) and when it looks there it also finds, and returns,
named elements. But the method name and the W3C specs definitely suggest
that this is incorrect behaviour.

Richard.
Jul 20 '05 #6
On Sat, 17 Jan 2004 14:18:49 -0000, "Richard Cornford"
<Ri*****@litote s.demon.co.uk> wrote:
Yes I have noticed, and it looks like gEBI is optimised on IE to look up
the ID in the document.all collection (returning the first element of
collections found) and when it looks there it also finds, and returns,
named elements.


It's only incorrect behaviour if the doctype is an HTML one without an
internal subset, we know IE doesn't actually read the doctype or parse
it etc. it just has its own internal one. it's own internal one could
have NAME as type ID, and therefore all is fine if gEBI returns it.

Given that most people return invalid documents we definately can't
complain about DOM behaviour on those, if we return a valid HTML or
XHTML document that says NAME isn't an ID, then we can complain.

Jim.
--
comp.lang.javas cript FAQ - http://jibbering.com/faq/

Jul 20 '05 #7
"Jim Ley" <ji*@jibbering. com> wrote in message
news:40******** *******@news.ci s.dfn.de...
<snip>
Given that most people return invalid documents we definately
can't complain about DOM behaviour on those, if we return a
valid HTML or XHTML document that says NAME isn't an ID, then
we can complain.


I always forget that HTML can be valid and unusual if it has its own
custom DTD. Or more precisely, I don't forget I just disregard the
possibility as I see little reason for doing that, and it wouldn't alter
the scriptability of the resulting DOM in HTML browsers (because, as you
say, they aren’t interested in the DTD anyway).

OK, gEBI should be expected to have its W3C Core DOM specified behaviour
in a valid HTML 4 (with standard DTD) document, but should anything be
expected from an invalid document?

Richard
Jul 20 '05 #8
On Sun, 18 Jan 2004 07:06:28 -0000, "Richard Cornford"
<Ri*****@litote s.demon.co.uk> wrote:
but should anything be
expected from an invalid document?


All bets are off on invalid documents. Standards can only really talk
about what conforming user agents do to its own valid documents.

Invalid documents could simply be adhering to a different standard,
and text/html puts no limits on what can be served as it.

Jim.
--
comp.lang.javas cript FAQ - http://jibbering.com/faq/

Jul 20 '05 #9

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

Similar topics

2
9586
by: Greg | last post by:
I'm trying to understand getElementByID a bit better. When I try the following... if (parseFloat(document.getElementByID('QuantityMade').value) > 0) { alert('it seems to exist'); } (the text field QuantityMade holds a value of 17)
7
1335
by: Gerry | last post by:
Hi, I have a javascript function which uses the method document.getElementById. I'm using it to decide whether a checkbox has been ticked or not. This decision is encoded in an if statement with the condtion being if (document.getElementById(checkboxtoupdate).value ==1)
1
2692
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff working, but it only worked for IE. You can see a working version here: http://www.publicpen.com/designer/mcControlPanel.php username: designer...
4
5452
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) { document.getElementById(nameOfDiv).style.visibility='visible'; document.getElementById(nameOfDiv).style.height='auto'; if (nameOfDiv != 'weblogs')
10
2661
by: JJA | last post by:
I'm trying to use document.getElementByID inside a function where the ID is passed as an argument. I get the same error ("Element has no properties") on the same statement inside the commonCheck function with either MS IE 6.0 or Mozilla Firefox 0.9. Comments below indicate that if I hardcode an element ID I can avoid the error, but I...
2
24637
by: Dave Hammond | last post by:
I've got what should be a simple assignment of either an element value or a default string to a variable, but when the element doesn't exist I get an "Object required" error rather than an assignment of the default value. I originally used the simple statement: var v = document.getElementById('foo').value ||...
5
4419
by: HopfZ | last post by:
I made two shortcut functions for document.getElementById as: function EBI2(id){return document.getElementById(id)}; var EBI3 = document.getElementById; But EBI3 don't work. EBI2('myText'); //works EBI3('myText'); //unexpected error
4
2612
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an iframe's src property. Being that IE does not follow standard and considers an id, name, etc as a qualifying identifier for the document.getElementById...
29
19174
by: Nick | last post by:
I've seen a few frameworks use the following: function $(id) { return document.getElementById(id); } Then to use: $('something').innerHTML = 'blah'; I'm just trying to roll this out to my site and so far doing this has saved about 8KB of javascript (lots of ajax/dynamic elements). I just
1
2223
by: vikD | last post by:
Hello, I'm really bad at javascript but I managed to get the code below to work in IE but firefox gives this error... Error: document.getElementById.formall is undefined Basically use the script to update the display to the user depending on what they choose (qty, options, shipping etc.) I'm sure it's simple but I could really use a...
0
7669
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
7926
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...
1
7439
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
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
5343
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
4962
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...
0
3450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
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
0
722
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.