471,596 Members | 826 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 software developers and data experts.

strange problem.... its probably me... but object expected..

I play around with js a little... I just don't get this.

The file below is just trying out some things... it does exactly what
I want (hides/displays some things, no big deal)

The problem is that in the swapcheck(x) function below, if I uncomment
the first line (commented with //) the whole thing brings and IE
errors the page with an object expected error on line (whichever input
control I clicked).

swapcheck isn't even getting called. I don't get why it is breaking
the page.

Any help greatly appreciated.

(note that if you try this file, you will need to create two css files
to link to)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
<!--
function changeIt()
{
if (document.all.theLine.style.display=='none') {
document.all.theLine.style.display=''
}
else {
document.all.theLine.style.display='none'
}
}
-->
</script>
<script language="javascript">
<!--
function swapcheck(x) {
// if document.form1.calcat1.checked { } ' this line here!
}
function swapdisplay(x) {
x--
var theSheet=document.styleSheets[1]
var theRule=theSheet.cssRules? theSheet.cssRules[x]:
theSheet.rules[x]
if (theRule.style.display=="block") {
theRule.style.display="none" }
else {
theRule.style.display="block" }
}
-->
</script>
<link href="newfbc.css" rel="stylesheet" type="text/css" />
<link href="calcats.css" rel="stylesheet" type="text/css" />

</head>

<body>
The next line should disappear and then reappear.
<div id="theLine" class="dynamic">This is the one</div>
<div id="notTheLine" class="static">This one should stay</div>
<p>
<form name="form1" method="post" action="">
<input type="button" onclick="changeIt()" value="Change!" />
<p>
<p class="calcat1">Category 1 </p>
<p class="calcat2">Category 2 </p>
<p class="calcat3">Category 3 </p>
<p class="calcat4">Category 4 </p>
<p class="calcat5">Category 5 </p>
<p class="calcat6">Category 6 </p>
<p class="calcat7">Category 7 </p>
<p class="calcat8">Category 8 </p>
<p class="calcat9">Category 9 </p>
<p></p>
<p><br />

<input type="button" value="1" onclick="swapdisplay(1)" />

<input type="button" value="2" onclick="swapdisplay(2)" />

<input type="button" value="3" onclick="swapdisplay(3)" />

<input type="button" value="4" onclick="swapdisplay(4)" />

<input type="button" value="5" onclick="swapdisplay(5)" />

<input type="button" value="6" onclick="swapdisplay(6)" />

<input type="button" value="7" onclick="swapdisplay(7)" />

<input type="button" value="8" onclick="swapdisplay(8)" />

<input type="button" value="9" onclick="swapdisplay(9)" />

<table>
<tr>

<td>Category 1&nbsp;
<input type="checkbox" name="calcat"
onclick="swapdisplay(1)" />
</td>

<td>Category 2&nbsp;
<input type="checkbox" name="calcat"
onclick="swapdisplay(2)" />
</td>

<td>Category 3&nbsp;
<input type="checkbox" name="calcat"
onclick="swapdisplay(3)" />
</td>

<td>Category 4&nbsp;
<input type="checkbox" name="calcat"
onclick="swapdisplay(4)" />
</td>

<td>Category 5&nbsp;
<input type="checkbox" name="calcat"
onclick="swapdisplay(5)" />
</td>

<td>Category 6&nbsp;
<input type="checkbox" name="calcat"
onclick="swapdisplay(6)" />
</td>

<td>Category 7&nbsp;
<input type="checkbox" name="calcat"
onclick="swapdisplay(7)" />
</td>

<td>Category 8&nbsp;
<input type="checkbox" name="calcat"
onclick="swapdisplay(8)" />
</td>

<td>Category 9&nbsp;
<input type="checkbox" name="calcat"
onclick="swapdisplay(9)" />
</td>

</tr>
</table>
</form>
</body>
</html>

Apr 9 '06 #1
11 1829
Dagwood Bumstead wrote:
I play around with js a little... I just don't get this.

The file below is just trying out some things... it does exactly what
I want (hides/displays some things, no big deal)

The problem is that in the swapcheck(x) function below, if I uncomment
the first line (commented with //) the whole thing brings and IE
errors the page with an object expected error on line (whichever input
control I clicked).

</script>
<script language="javascript">
type="text/javascript"
<!--
function swapcheck(x) {
// if document.form1.calcat1.checked { } ' this line here!


Not a well formed if.

Use Firefox for more meaningful error messages.

--
Ian Collins.
Apr 9 '06 #2
I came back to say I found it... you answered in like 9 minutes...
wow.

Thanks.

I'll take your advice on FF.


On Sun, 09 Apr 2006 15:24:21 +1200, Ian Collins <ia******@hotmail.com>
wrote:
Dagwood Bumstead wrote:
I play around with js a little... I just don't get this.

The file below is just trying out some things... it does exactly what
I want (hides/displays some things, no big deal)

The problem is that in the swapcheck(x) function below, if I uncomment
the first line (commented with //) the whole thing brings and IE
errors the page with an object expected error on line (whichever input
control I clicked).

</script>
<script language="javascript">


type="text/javascript"
<!--
function swapcheck(x) {
// if document.form1.calcat1.checked { } ' this line here!


Not a well formed if.

Use Firefox for more meaningful error messages.

Apr 9 '06 #3
Dagwood Bumstead wrote:
<snip>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
You think this is an XHTML document? Don't fool yourself, it is not. It
is best to avoid XHTML (and/or the illusion of XHTML) in favour of HTML
if you intend to script the document.
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
The TYPE attribute is required in SCRIPT elements in both valid HTML and
XHTML documents, and once provided the deprecated LANGUAGE attribute
becomes redundant.
<!--
The practice of 'hiding scripts form older browser' with the use of HTML
comment-like structures has long since become redundant. It is also
seriously dangerous in XHTML documents as XML parsers are allowed to
strip all comments from the mark-up, taking the apparently commented-out
script with them. So it is a good thing that this document only gives
the illusion of being XHTML rather than being the real thing.
function changeIt()
{
if (document.all.theLine.style.display=='none') {
document.all.theLine.style.display=''
The - document.all - collection is a Microsoft/IE proprietary collection
(implemented in a number of imitators) but as IE has no conception of
XHTML the use of - document.all - flags this document as a tag-soup HTML
document despite its misleading syntax and doctype declaration.
}
else {
document.all.theLine.style.display='none'
}
}
-->
If these HTML comment-like structures are going to be used (and they
should not) then the closing '-->', appearing at the end of the contents
of a script element are a syntax error that only a few browsers will
disregard. The accepted and safe (but still redundant) form is to
precede the '-->' with '//' so that the whole looks like an end of line
comment to the script interpreter.
</script>
<script language="javascript">
<!--
function swapcheck(x) {
// if document.form1.calcat1.checked { } ' this line here!

<snip>

Should be:-

if (document.form1.calcat1.checked) { }

-, with parentheses around the expression. Otherwise it is a syntax
error and the functions defined in the containing script element are not
created. Because the functions are not created attempting to call these
now non-existent functions results in an 'object expected' error.

In IE's pop-up javascript error box, check the checkbox that says
'Always display this message when a page contains errors' and then the
box will open when the syntax error happens and you will not miss it.

Incidentally, the 'shortcut' form accessor - document.form1 - should not
be expected to be available in XHTML DOMs as it is non-standard, so if
this document ever is interpreted as XHTML instead of tag-soup HTML the
script will error here (or at the earlier - document.all - use). You
would use - doucment.forms['form1'].elements['calcat1'] -(or its
dot-notation variants) in an XHTML DOM, and may as well do that anyway
as that form of property accessor is also available in HTML DOMs.

Richard.
Apr 9 '06 #4
But it brings up another question (which I guess is obvious)

So javascript interpreters check all code rather it gets called or
not?

Why, when the offending if was function bound, did it affect the other
part of the script?


On Sun, 09 Apr 2006 15:24:21 +1200, Ian Collins <ia******@hotmail.com>
wrote:
Dagwood Bumstead wrote:
I play around with js a little... I just don't get this.

The file below is just trying out some things... it does exactly what
I want (hides/displays some things, no big deal)

The problem is that in the swapcheck(x) function below, if I uncomment
the first line (commented with //) the whole thing brings and IE
errors the page with an object expected error on line (whichever input
control I clicked).

</script>
<script language="javascript">


type="text/javascript"
<!--
function swapcheck(x) {
// if document.form1.calcat1.checked { } ' this line here!


Not a well formed if.

Use Firefox for more meaningful error messages.

Apr 9 '06 #5
Gosh, Dick.... 60 lines of XHTML-purist, holier-than-thou spanking
before you even attempt to answer my question.

Thanks for the effort.

I didn't think it was XHTML... didn't care...mm stuck that in there
and I didn't bother changing it because I was just playing around
trying to get my head around something I didn't understand, the page
was never going live.

I'm not sure you intended to help as much as you intended to
denigrate, but I will take information from your post. Such as, I'm
never going to move to XHTML because I script everything, though
typically serverside.

Deprecated LANGUAGE attribute; redundant <!-- --> markers? You found
me out: I'm not a young college whippersnapper. Back in the day,
everybody was adamant these things be used. Sorry I haven't kept up
with clientside advances.

Which is why I had the question in the first place. All this new
fangled AJAX stuff has me moving back to client scripting. I'll try to
do better in the future.

Regards.

On Sun, 9 Apr 2006 05:06:49 +0100, "Richard Cornford"
<Ri*****@litotes.demon.co.uk> wrote:
Dagwood Bumstead wrote:
<snip>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


You think this is an XHTML document? Don't fool yourself, it is not. It
is best to avoid XHTML (and/or the illusion of XHTML) in favour of HTML
if you intend to script the document.
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">


The TYPE attribute is required in SCRIPT elements in both valid HTML and
XHTML documents, and once provided the deprecated LANGUAGE attribute
becomes redundant.
<!--


The practice of 'hiding scripts form older browser' with the use of HTML
comment-like structures has long since become redundant. It is also
seriously dangerous in XHTML documents as XML parsers are allowed to
strip all comments from the mark-up, taking the apparently commented-out
script with them. So it is a good thing that this document only gives
the illusion of being XHTML rather than being the real thing.
function changeIt()
{
if (document.all.theLine.style.display=='none') {
document.all.theLine.style.display=''


The - document.all - collection is a Microsoft/IE proprietary collection
(implemented in a number of imitators) but as IE has no conception of
XHTML the use of - document.all - flags this document as a tag-soup HTML
document despite its misleading syntax and doctype declaration.
}
else {
document.all.theLine.style.display='none'
}
}
-->


If these HTML comment-like structures are going to be used (and they
should not) then the closing '-->', appearing at the end of the contents
of a script element are a syntax error that only a few browsers will
disregard. The accepted and safe (but still redundant) form is to
precede the '-->' with '//' so that the whole looks like an end of line
comment to the script interpreter.
</script>
<script language="javascript">
<!--
function swapcheck(x) {
// if document.form1.calcat1.checked { } ' this line here!

<snip>

Should be:-

if (document.form1.calcat1.checked) { }

-, with parentheses around the expression. Otherwise it is a syntax
error and the functions defined in the containing script element are not
created. Because the functions are not created attempting to call these
now non-existent functions results in an 'object expected' error.

In IE's pop-up javascript error box, check the checkbox that says
'Always display this message when a page contains errors' and then the
box will open when the syntax error happens and you will not miss it.

Incidentally, the 'shortcut' form accessor - document.form1 - should not
be expected to be available in XHTML DOMs as it is non-standard, so if
this document ever is interpreted as XHTML instead of tag-soup HTML the
script will error here (or at the earlier - document.all - use). You
would use - doucment.forms['form1'].elements['calcat1'] -(or its
dot-notation variants) in an XHTML DOM, and may as well do that anyway
as that form of property accessor is also available in HTML DOMs.

Richard.

Apr 9 '06 #6
Dagwood Bumstead wrote:
Gosh, Dick.... 60 lines of XHTML-purist, holier-than-thou spanking
before you even attempt to answer my question.
A think skin and a decent sense of humour are essential assets around here!
Which is why I had the question in the first place. All this new
fangled AJAX stuff has me moving back to client scripting. I'll try to
do better in the future.

It's also fun, don't be put off.

--
Ian Collins.
Apr 9 '06 #7
Dagwood Bumstead wrote:
<snip>
I'm not sure you intended to help as much as you
intended to denigrate, ... <snip>

If you want to take it that way I won't bother with you in future.
On Sun, 9 Apr 2006 05:06:49 +0100, "Richard Cornford"
<Ri*****@litotes.demon.co.uk> wrote:

<snip: full-quote, top-posted over>

And I probably won't be alone in that.

Richard.
Apr 10 '06 #8
Richard Cornford wrote:
[...]
If you want to take it that way I won't bother with you in future.
On Sun, 9 Apr 2006 05:06:49 +0100, "Richard Cornford"

<Ri*****@litotes.demon.co.uk> wrote:
<snip: full-quote, top-posted over>

And I probably won't be alone in that.


Yes, you are not. There is so much to be read around
here; one does not need to read postings like those.
Regards,
PointedEars
Apr 10 '06 #9
Sorry guys, I was just replying in kind.

My apologies to all who were offended.

Regards.

On Sun, 09 Apr 2006 22:33:44 GMT, Dagwood Bumstead
<db*******@jcdithers.com> wrote:
Gosh, Dick.... 60 lines of XHTML-purist, holier-than-thou spanking
before you even attempt to answer my question.

Thanks for the effort.

I didn't think it was XHTML... didn't care...mm stuck that in there
and I didn't bother changing it because I was just playing around
trying to get my head around something I didn't understand, the page
was never going live.

I'm not sure you intended to help as much as you intended to
denigrate, but I will take information from your post. Such as, I'm
never going to move to XHTML because I script everything, though
typically serverside.

Deprecated LANGUAGE attribute; redundant <!-- --> markers? You found
me out: I'm not a young college whippersnapper. Back in the day,
everybody was adamant these things be used. Sorry I haven't kept up
with clientside advances.

Which is why I had the question in the first place. All this new
fangled AJAX stuff has me moving back to client scripting. I'll try to
do better in the future.

Regards.

On Sun, 9 Apr 2006 05:06:49 +0100, "Richard Cornford"
<Ri*****@litotes.demon.co.uk> wrote:
Dagwood Bumstead wrote:
<snip>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


You think this is an XHTML document? Don't fool yourself, it is not. It
is best to avoid XHTML (and/or the illusion of XHTML) in favour of HTML
if you intend to script the document.
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">


The TYPE attribute is required in SCRIPT elements in both valid HTML and
XHTML documents, and once provided the deprecated LANGUAGE attribute
becomes redundant.
<!--


The practice of 'hiding scripts form older browser' with the use of HTML
comment-like structures has long since become redundant. It is also
seriously dangerous in XHTML documents as XML parsers are allowed to
strip all comments from the mark-up, taking the apparently commented-out
script with them. So it is a good thing that this document only gives
the illusion of being XHTML rather than being the real thing.
function changeIt()
{
if (document.all.theLine.style.display=='none') {
document.all.theLine.style.display=''


The - document.all - collection is a Microsoft/IE proprietary collection
(implemented in a number of imitators) but as IE has no conception of
XHTML the use of - document.all - flags this document as a tag-soup HTML
document despite its misleading syntax and doctype declaration.
}
else {
document.all.theLine.style.display='none'
}
}
-->


If these HTML comment-like structures are going to be used (and they
should not) then the closing '-->', appearing at the end of the contents
of a script element are a syntax error that only a few browsers will
disregard. The accepted and safe (but still redundant) form is to
precede the '-->' with '//' so that the whole looks like an end of line
comment to the script interpreter.
</script>
<script language="javascript">
<!--
function swapcheck(x) {
// if document.form1.calcat1.checked { } ' this line here!

<snip>

Should be:-

if (document.form1.calcat1.checked) { }

-, with parentheses around the expression. Otherwise it is a syntax
error and the functions defined in the containing script element are not
created. Because the functions are not created attempting to call these
now non-existent functions results in an 'object expected' error.

In IE's pop-up javascript error box, check the checkbox that says
'Always display this message when a page contains errors' and then the
box will open when the syntax error happens and you will not miss it.

Incidentally, the 'shortcut' form accessor - document.form1 - should not
be expected to be available in XHTML DOMs as it is non-standard, so if
this document ever is interpreted as XHTML instead of tag-soup HTML the
script will error here (or at the earlier - document.all - use). You
would use - doucment.forms['form1'].elements['calcat1'] -(or its
dot-notation variants) in an XHTML DOM, and may as well do that anyway
as that form of property accessor is also available in HTML DOMs.

Richard.

Apr 10 '06 #10
an addition to this....

use Firebug
(https://addons.mozilla.org/extension...fo.php?id=1843) in Firefox
to get more about Javascript errors... it really helps a lot

Apr 10 '06 #11
nairs wrote:
an addition to this....

use Firebug
(https://addons.mozilla.org/extension...fo.php?id=1843) in Firefox
to get more about Javascript errors... it really helps a lot


FireBug is a Firefox extension that definitely can be recommended for Web
development, including JavaScript debugging (I use it myself), but it does
not show more (about) JavaScript errors than Firefox's built-in JavaScript
Console or the Console^2 extension.
PointedEars
Apr 10 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Wolfgang.Stoecher | last post: by
reply views Thread by Ethel Aardvark | last post: by
3 posts views Thread by Michael Meckelein | last post: by
11 posts views Thread by Martin Joergensen | last post: by
7 posts views Thread by ChrisM | last post: by
reply views Thread by maryjones11289 | last post: by
7 posts views Thread by lothar.behrens | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.