473,841 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitl ed Document</title>
<script language="javas cript">
<!--
function changeIt()
{
if (document.all.t heLine.style.di splay=='none') {
document.all.th eLine.style.dis play=''
}
else {
document.all.th eLine.style.dis play='none'
}
}
-->
</script>
<script language="javas cript">
<!--
function swapcheck(x) {
// if document.form1. calcat1.checked { } ' this line here!
}
function swapdisplay(x) {
x--
var theSheet=docume nt.styleSheets[1]
var theRule=theShee t.cssRules? theSheet.cssRul es[x]:
theSheet.rules[x]
if (theRule.style. display=="block ") {
theRule.style.d isplay="none" }
else {
theRule.style.d isplay="block" }
}
-->
</script>
<link href="newfbc.cs s" rel="stylesheet " type="text/css" />
<link href="calcats.c ss" 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="change It()" 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="swapdi splay(1)" />

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

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

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

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

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

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

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

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

<table>
<tr>

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

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

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

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

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

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

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

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

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

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

Apr 9 '06 #1
11 1931
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="javas cript">
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******@hotma il.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="javas cript">


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.dt d">
<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>Untitl ed Document</title>
<script language="javas cript">
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.t heLine.style.di splay=='none') {
document.all.th eLine.style.dis play=''
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.th eLine.style.dis play='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="javas cript">
<!--
function swapcheck(x) {
// if document.form1. calcat1.checked { } ' this line here!

<snip>

Should be:-

if (document.form1 .calcat1.checke d) { }

-, 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******@hotma il.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="javas cript">


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*****@litote s.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.dt d">
<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>Untitl ed Document</title>
<script language="javas cript">


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.t heLine.style.di splay=='none') {
document.all.th eLine.style.dis play=''


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.th eLine.style.dis play='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="javas cript">
<!--
function swapcheck(x) {
// if document.form1. calcat1.checked { } ' this line here!

<snip>

Should be:-

if (document.form1 .calcat1.checke d) { }

-, 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*****@litote s.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*****@litote s.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*******@jcdi thers.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*****@litot es.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.dt d">
<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>Untitl ed Document</title>
<script language="javas cript">


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.t heLine.style.di splay=='none') {
document.all.th eLine.style.dis play=''


The - document.all - collection is a Microsoft/IE proprietary collection
(implemente d 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.th eLine.style.dis play='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="javas cript">
<!--
function swapcheck(x) {
// if document.form1. calcat1.checked { } ' this line here!

<snip>

Should be:-

if (document.form1 .calcat1.checke d) { }

-, 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.

Incidentall y, 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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1478
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 be altered !?
0
2707
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 switch on and off certain rules. One idea I had was to have two queries UNIONed together with a simple switch selecting which half was to operate (I know it sounds like there are probably better ways of doing this but I have my reasons). To cut...
4
6110
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 application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component for this, and a test application for the component. It allows me to specify a command to execute,...
3
1824
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 moveItem = lv.SelectedItems; selIdx = moveItem.Index; // ignore movedown of last item
11
2602
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 temperatures. T = 20 degrees at all times.... The 2D T-array looks like this:
6
2284
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 the same method (aka delegate?). I use the Tag property within this method to determine what user action is taking place. Very simple: When adding toolbar button: tbButton.Click += new...
7
1448
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 complicated application which seems to me to be misbehaving. The following is an attempt to reproduce the error. There are reasons in the real application why I'm trying to do things the way they are here, so please no comments on techniques here,...
0
1342
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, defining grid columns then binding it to my table etc. Several of the columns in the gridview are of type ButtonField with ButtonType set to "Button" Now, all of this is working fine...no problems whatsoever.
7
1563
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 inside Finalize. The sample code at the end crashes when I not do a call to getReader with an empty string. That is used as a Dummy for ' This object is used until here '
0
9865
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9706
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10927
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10667
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7848
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7025
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5880
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.