473,320 Members | 2,161 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,320 software developers and data experts.

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='prioritySelect' class='selectwidth'>
<option value=''>Choose one</option>
<option value='1'>Critical</option>
<option value='2'>High</option>
<option value='3'>Medium</option>
<option value='4'>Low</option>
</select>
....
</form>

And the related javascript code:
if(document.getElementById("prioritySelect").disab led == false)
{ ... }

When digging into this I can get the desired information by using
document.task.prioritySelect, 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 2496
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='prioritySelect' class='selectwidth'>


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*****@crossnet.se> wrote in message
news:49**************************@posting.google.c om...
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='prioritySelect' class='selectwidth'>
This element has no ID attribute.

<snip>And the related javascript code:
if(document.getElementById("prioritySelect").disa bled == 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.prioritySelect,
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********@jimdabell.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='prioritySelect' class='selectwidth'>


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*****@litotes.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.uniqueID;
el=document.getElementById(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.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #5
"Jim Ley" <ji*@jibbering.com> wrote in message
news:40***************@news.cis.dfn.de...
On Thu, 15 Jan 2004 14:20:48 -0000, "Richard Cornford"
<Ri*****@litotes.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.uniqueID;
el=document.getElementById(a);
alert(el+','+el.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*****@litotes.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.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #7
"Jim Ley" <ji*@jibbering.com> wrote in message
news:40***************@news.cis.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*****@litotes.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.javascript 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
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...
7
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...
1
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...
4
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) {...
10
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...
2
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...
5
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');...
4
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...
29
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...
1
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.