473,378 Members | 1,343 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,378 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 1887
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Wolfgang.Stoecher | last post by:
Hello, I'm new to Python and playing around. I'm confused by the following behaviour: >>> l1 = # define list >>> l2 = l1 # copy of l1 ? >>> l2,l1 (, ) >>> l2.extend(l1) # only l2 should...
0
by: Ethel Aardvark | last post by:
I am running a 9.0.1 database on a W2K server and have come across some strange behaviour with a SQL query. I have a query which runs in a PL/SQL cursor which has several PL/SQL variables used to...
4
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
3
by: Michael Meckelein | last post by:
Hello, I run into trouble move down a selected item in a listbox. The code moving down the item is the following one: for (int j = lv.SelectedItems.Count-1; j >=0; j--) { ListViewItem...
11
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
7
by: ChrisM | last post by:
I posted this last week, so apologies for re-posting but I'm still looking for a sensible answer, and I'm hoping somone new might be able to cast some light... Basically, I have a fairly...
0
by: maryjones11289 | last post by:
Hi, I have a strange problem that hopefully someone can advise me on... I have a Gridview which is not bound to a dataset etc. I populate the gridview manually by constructing my own table,...
7
by: lothar.behrens | last post by:
Hi, I have figured out that .NET CLR implements object destruction on the knowledge of usage of these objects. My DBHelper class closes the connection when refcount goes to zero. That happens...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.