item not defined using Mozilla?

L

LRW

I have a Javascript that makes a tablerow visible ot invisible, that
works fine in InternetExplorer, but in Mozilla it's unresponsive and I
get the following Javascript Console error:
Error: itemeditrow is not defined
Source File: editform.php
Line: 45

Below is the Javascript, and a section of the HTML for that tablerow.

I don't get it. It looks defined to me. What am I missing?

Thanks for any help!
Liam

<!-- Begin
function makeItemEditVis()
{
itemeditrow.style.visibility = 'visible';
itemeditrow2.style.visibility = 'visible';
}
// End -->

<tr class="label" id="itemeditrow" style="visibility:hidden"><td
colspan="3" class="labelBlue" bgcolor=#E6EDF5>item #:
etc....
 
L

Lasse Reichstein Nielsen

I have a Javascript that makes a tablerow visible ot invisible, that
works fine in InternetExplorer, but in Mozilla it's unresponsive and I
get the following Javascript Console error:
Error: itemeditrow is not defined ....

itemeditrow.style.visibility = 'visible';
itemeditrow2.style.visibility = 'visible'; ....
<tr class="label" id="itemeditrow" style="visibility:hidden"><td

Check <URL:http://jibbering.com/faq/#FAQ4_41>

/L
 
M

Mick White

LRW said:
Thanks for any help!
Liam

<!-- Begin
function makeItemEditVis()
{
itemeditrow.style.visibility = 'visible';

The reference to itemitrow is wrong. Use the dom heirarchy to reference it.
Mick
 
L

LRW

Lasse Reichstein Nielsen said:

Thanks for the reply!
So, odd. I changed the lines to:
document.form1.itemeditrow.style.visibility = 'visible';
document.form1.itemeditrow2.style.visibility = 'visible';
And I no longer get the "not defined" error, except, now not only does
it not work in Mozilla but also stopped working in IE.

And the form tag has name="form1". Then I added id="form1" but no
change.

I have no idea if this is related, but in the Mozilla JavaScript
Console I'm also getting the error:

"document.form1.itemeditrow has no properties"
It's refering to the line that has:
document.form1.itemeditrow.style.display = 'block';

Isn't 'block' a property for "display"?

=P
Thanks for the help!
Liam
 
M

Michael Winter

[snip]
Thanks for the reply!
So, odd. I changed the lines to:
document.form1.itemeditrow.style.visibility = 'visible';
document.form1.itemeditrow2.style.visibility = 'visible';
And I no longer get the "not defined" error, except, now not only does
it not work in Mozilla but also stopped working in IE.

Can you answer this question: How does placing a table row in a form allow
you to access that row as if it were a form control?

Logic alone should tell you that it doesn't. There is no correlation
between form controls and table components. It appears that you missed the
point of the link Lasse gave you. You need to access the row using the id,
but in a cross-browser fashion.

if(document.getElementById) {
var itmRow = document.getElementById('itemeditrow');

if(itmRow && itmRow.style) {
itmRow.style.display = 'block';
}
}

[snip]
I have no idea if this is related, but in the Mozilla JavaScript
Console I'm also getting the error:

"document.form1.itemeditrow has no properties"
It's refering to the line that has:
document.form1.itemeditrow.style.display = 'block';

Isn't 'block' a property for "display"?

Yes, it is, but that's not the error. Because the form doesn't contain the
row, document.form1.itemeditrow evaluates to undefined. Obviously, you
can't access a property that doesn't exist, and that's why Mozilla says
that document.form1.itemeditrow has no properties.

Hope that helps,
Mike
 
T

Thomas 'PointedEars' Lahn

LRW said:

Please do not write attribution novels.

Please trim your quotes.
So, odd. I changed the lines to:
document.form1.itemeditrow.style.visibility = 'visible';
document.form1.itemeditrow2.style.visibility = 'visible';
And I no longer get the "not defined" error, except, now not only does
it not work in Mozilla but also stopped working in IE.

There is no (form) element with ID "itemeditrow2" in your document.
And the form tag has name="form1".

It is not the "form tag", there is no such thing. You mean the "form"
element and have the initial value of the "name" attribute of that element
replaced with the value "form1" by including an attribute-value pair in
its start tag ( said:
Then I added id="form1" but no
change.

Of course not.
I have no idea if this is related, but in the Mozilla JavaScript
Console I'm also getting the error:

"document.form1.itemeditrow has no properties"

It is very much related. This is because null/undefined has no properties.
It's refering to the line that has:
document.form1.itemeditrow.style.display = 'block';

Isn't 'block' a property for "display"?

No, `display' is a (CSS) property and `block' is a possible value for it.

However, if you refer to the form and then want to refer to an element of
the form by its ID, you must use the square bracket property accessor and
the "elements" collection. You should also use the "forms" collection:

document.forms['form1'].elements['itemeditrow'].style.display = 'block';

However, you don't want to refer to a form element, i.e. "input" and the
like, so the target element is _not_ part of the "elements" collection of
the HTMLFormElement object. The following should work:

<head>
<title>...</title>
...
<script type="text/javascript">
function makeItemEditVis()
{
var t;
if ((t = typeof document.getElementById) == "function"
|| (t == "object" && document.getElementById))
{
for (var i = arguments.length; i--;)
{
var o = document.getElementById(arguments);
if (o
&& typeof o.style != "undefined"
&& typeof o.style.visibility != "undefined")
{
o.style.visibility = 'visible';
}
}
}
}
</script>

<style type="text/css">
.labelBlue {
background-color:#ccf;
color:#000;
}
</style>
</head>

<body>
<form action="...">
<table>
<tr class="label" id="itemeditrow" style="visibility:hidden">
<td colspan="3" class="labelBlue">item #:</td>
...
</tr>
...
</table>
...
<script type="text/javascript">
document.write(
'<input type="button"'
+ ' onclick="makeItemEditVis(\'itemeditrow\','
+ ' \'itemeditrow2\');">');
</script>
...
</form>

As you can see, do not mix CSS and formatting attributes, and use
secure colors only; also remove the SGML Comment Opener and Closer,
they are obsolete (even though it is described differently in the
HTML 4.01 Specification).


HTH

PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Mon, 20 Sep
2004 19:41:55, seen in Thomas 'PointedEars'
Lahn said:
Please do not write attribution novels.

It is permissible for Lahn's home hierarchy, to hold such
views. But, like the events of 1939-09-01 and 1940-04-09, it is now
internationally considered to be a Mistake.

Present Usenet thinking encourages proper attributions; see Usefor work-
in-progress at
http://www.ietf.org/internet-drafts/draft-ietf-usefor-useage-00.txt
http://www.ietf.org/internet-drafts/draft-ietf-usefor-article-13.txt


An informative attribution would have made it clear that the idiot
savant child Lahn is, once more, contributing to an ancient thread.


<FAQENTRY>
The FAQ should cite the above, or successor, documents; and perhaps also
that in sig line 2, which is so widely useful.
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top