Netscape 7.1 getElementById Error

G

Gerry

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)


/* The Code */

function set(object)
{
var checkboxtoupdate = object.value;

if (document.getElementById(checkboxtoupdate).value ==1)
document.getElementById(checkboxtoupdate).value = 0;
else
document.getElementById(checkboxtoupdate).value = 1;
}



The "object" accesses a html tag which has an value attribute e.g
value="7400"

However Netscape Navigator 7.1 does not seem to recognise
"document.getElementById(checkboxtoupdate).value"
and reports an error that
document.getElementById(checkboxtoupdate).value has no properties.

But Internet Explorer has no problem with this at all.

Is there another way to do this so as to be recognised by Netscape
7.1?
 
Z

ZER0

On 7 Apr 2004 02:30:10 -0700, Gerry wrote:

[cut]
function set(object)
{
var checkboxtoupdate = object.value;

if (document.getElementById(checkboxtoupdate).value ==1) [cut]
The "object" accesses a html tag which has an value attribute e.g
value="7400"

However Netscape Navigator 7.1 does not seem to recognise
"document.getElementById(checkboxtoupdate).value"
and reports an error that
document.getElementById(checkboxtoupdate).value has no properties.

It's right.
But Internet Explorer has no problem with this at all.

The behavior of IE is wrong. Or better, it doesn't fit standards.

From W3C:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed
by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
colons (":"), and periods (".").

--
C'ya,
ZER0 :: coder.gfxer.webDesigner();

Deformazione professionale è:
Quando in ascensore senti la ragazza accanto che tira fuori il cellulare,
e ti volti per capire se e' un modello sul quale puoi sviluppare in J2ME.
 
M

Martin Honnen

Gerry wrote:

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)


/* The Code */

function set(object)
{
var checkboxtoupdate = object.value;

if (document.getElementById(checkboxtoupdate).value ==1)
document.getElementById(checkboxtoupdate).value = 0;
else
document.getElementById(checkboxtoupdate).value = 1;
}



The "object" accesses a html tag which has an value attribute e.g
value="7400"

Is there any element in the page that has
<tagname id="7400">
?? I guess you don't have one but only
<tagname name="7400">
 
I

Ivo

I'm using it to decide whether a checkbox has been ticked or not.

There is a word for that in javascript: checked. It is an ordinary
read/write property of any element that can be ticked and unticked. For
example this line
if(obj.checked==true) obj.checked= false
would see whether the object "obj" is currently ticked, and if so, untick
it.
function set(object)
{
var checkboxtoupdate = object.value;

So checkboxtoupdate is a value. Fine.
if (document.getElementById(checkboxtoupdate).value ==1)

So checkboxtoupdate not only *is* but also *has* a value of its own. Eh? Did
you not mean:
if (document.getElementById(object).value ==1)
document.getElementById(checkboxtoupdate).value = 0;
else
document.getElementById(checkboxtoupdate).value = 1;
}

The "object" accesses a html tag which has an value attribute e.g
value="7400"

That would be the checkboxtoupdate variable then.
However Netscape Navigator 7.1 does not seem to recognise
"document.getElementById(checkboxtoupdate).value"
and reports an error that
document.getElementById(checkboxtoupdate).value has no properties.

But Internet Explorer has no problem with this at all. Is there another
way to do this so as to be recognised by Netscape 7.1?

No idea why this works in IE.
Ivo
 
A

Andy

I beleive your code should be

function set(object)
{
var checkboxtoupdate = object.value;

if (document.getElementById(checkboxtoupdate).checked ==true)
document.getElementById(checkboxtoupdate).checked = false;
else
document.getElementById(checkboxtoupdate).checked = true;
}
--
Andy

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)


/* The Code */

function set(object)
{
var checkboxtoupdate = object.value;

if (document.getElementById(checkboxtoupdate).value ==1)
document.getElementById(checkboxtoupdate).value = 0;
else
document.getElementById(checkboxtoupdate).value = 1;
}



The "object" accesses a html tag which has an value attribute e.g
value="7400"

However Netscape Navigator 7.1 does not seem to recognise
"document.getElementById(checkboxtoupdate).value"
and reports an error that
document.getElementById(checkboxtoupdate).value has no properties.

But Internet Explorer has no problem with this at all.

Is there another way to do this so as to be recognised by Netscape
7.1?
 
R

Randy Webb

Andy said:
I beleive your code should be

You would believe wrong.
function set(object)
{
var checkboxtoupdate = object.value;

if (document.getElementById(checkboxtoupdate).checked ==true)
document.getElementById(checkboxtoupdate).checked = false;
else
document.getElementById(checkboxtoupdate).checked = true;
}

checkboxtoupdate is a value of an element, as such, it has no "checked"
property.

And all of it is totally dependent on how object gets passed.

set(this.value);
set(this);
set('objectName);

And without knowing how set is called, and how object is passed, its
anybody's guess as to the problem.
 
G

Gerry

Hi again,

Thanks for your replys,
checkboxtoupdate is a value of an element, as such, it has no "checked"
property.

And all of it is totally dependent on how object gets passed.

set(this.value);
set(this);
set('objectName);

The object gets passed like this (in the webpage that is)
OnClick="parent.videoDetailSubmit.set(this)"

The full tag is as below.

The id is a different number for each checkbox.

<input type="checkbox" name="tom" id="{keyFrame/frame}"
value="{startTime}" OnClick="parent.videoDetailSubmit.set(this)"

a real example of the values for this:
<input OnClick="parent.videoDetailSubmit.set(this)" value="7400"
id="366" name="tom" type="checkbox">

In my code though i'm using the value attribute ,which 99.9% of the
time is unique but,in theory, it could be the same value for both
checkboxes, but when I try and use the unique "id" value , neither IE
or Netscape can seem to pick up on this with getElementById(object.id)
Why ever this happens I dont know.


Gerry.
 
M

Michael Winter

The object gets passed like this (in the webpage that is)
OnClick="parent.videoDetailSubmit.set(this)"

The full tag is as below.

The id is a different number for each checkbox.

<input type="checkbox" name="tom" id="{keyFrame/frame}"
value="{startTime}" OnClick="parent.videoDetailSubmit.set(this)">
</input>

INPUT elements do not, and cannot, have closing tags.

HTML: <input ...>
XHTML: said:
a real example of the values for this:
<input OnClick="parent.videoDetailSubmit.set(this)" value="7400"
id="366" name="tom" type="checkbox">

In my code though i'm using the value attribute ,which 99.9% of the
time is unique but,in theory, it could be the same value for both
checkboxes, but when I try and use the unique "id" value , neither IE
or Netscape can seem to pick up on this with getElementById(object.id)
Why ever this happens I dont know.

First, read ZER0's post; id values are illegal.

Second, why would you want to perform

document.getElementById( object.id );

where object is an element reference? It will simply return object, and so
the call will just be an expensive waste of time.

You've now managed to confuse the issue in my mind. First, it appeared
that the value of a control represented the id of another, and you wanted
to get a reference to that control through:

document.getElementById( object.value );

Now it appears that you want a reference to element passed, which you
already have in "object".

Mike


Please, don't top-post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top