Object Expected error

S

Shanimal

Hello-

I'm running a php front end app on mysql. When viewing the page with
Firefox, no error. When viewing with IE6, always get the following
error:

Line: 210
Char: 3
Error: Object expected
Code: 0

the error points to the following code:

for (i=0;i<9;i++) //number of folders here
{
switchDIV('f'+i);
}

specifically it points to the line with 2 blank spaces and switchDIV

Does anybody know of an easy way to fix this code? Do you need to see
more code to get an idea?

thank you!
PS
 
V

VK

Shanimal said:
Hello-

I'm running a php front end app on mysql. When viewing the page with
Firefox, no error. When viewing with IE6, always get the following
error:

Line: 210
Char: 3
Error: Object expected
Code: 0

the error points to the following code:

for (i=0;i<9;i++) //number of folders here
{
switchDIV('f'+i);
}

specifically it points to the line with 2 blank spaces and switchDIV

Does anybody know of an easy way to fix this code? Do you need to see
more code to get an idea?

This code is fine by itself (except you should declare i as local
instead of making it global: for (var i=0; i<9; i++)

Looks like IE6 cannot find switchDIV function. Are you sure it works
(means produces expected results) in Firefox? What switchDIV is? Do you
have a link to look at?
 
I

Ivo

"Shanimal"wrote
Hello-

I'm running a php front end app on mysql. When viewing the page with
Firefox, no error. When viewing with IE6, always get the following
error:

Line: 210
Char: 3
Error: Object expected
Code: 0

the error points to the following code:

for (i=0;i<9;i++) //number of folders here
{
switchDIV('f'+i);
}

specifically it points to the line with 2 blank spaces and switchDIV

Type in your IE addressbar this line of code:
javascript: alert( switchDIV );
This will tell you if IE knows about your function. If not, you get the
object exprected error message and the next step is finding out why (are
other functions also gone?). If it does, you see the code of the function,
and you know you need elsewhere.
hth
ivo
http://www.yorick.onlyfools.com/
 
S

Shanimal

Thanks for the help!

I checked and IE did't know about the function.

I made the change that VK suggested, and now the error is gone!

You guys rock for helping me out with this!

thanks again
PS
 
S

Shanimal

Major brain cramp! The change didn't eliminate the error at all. I
guess the browser I tested with already was set to ignore the error.
Sorry about that. Maybe if I include more code somebody can figure out
how I should declare the switchDIV variable.

<script type="text/javascript">
<!--
function switchUl(id){
if(document.getElementById){
a=document.getElementById(id);
a.style.display=(a.style.display!="none")?"none":"block";
}
}
for(var i=0;i<9;i++) //number of folders HERE
{
switchDIV('f'+i);
}
// -->
</SCRIPT>
 
M

Manifest Interactive

Shanimal said:
Major brain cramp! The change didn't eliminate the error at all. I
guess the browser I tested with already was set to ignore the error.
Sorry about that. Maybe if I include more code somebody can figure out
how I should declare the switchDIV variable.

<script type="text/javascript">
<!--
function switchUl(id){
if(document.getElementById){
a=document.getElementById(id);
a.style.display=(a.style.display!="none")?"none":"block";
}
}
for(var i=0;i<9;i++) //number of folders HERE
{
switchDIV('f'+i);
}
// -->
</SCRIPT>

Greetings,

You'll hate yourself for this, but I do it all the time. You are
calling a function called switchDIV() when your actual function is
called switchUl();

Hope that helps,
- Peter Schmalfeldt
 
S

Shanimal

Peter-

I've tried both variations on this:

<script type="text/javascript">
<!--
function switchUl(id){
if(document.getElementById){
a=document.getElementById(id);
a.style.display=(a.style.display!="none")?"none":"block";
}
}
for(var i=0;i<9;i++) //number of folders HERE
{
switchUI('f'+i);
}
// -->
</SCRIPT>

and I also tried this:

<script type="text/javascript">
<!--
function switchDIV(id){
if(document.getElementById){
a=document.getElementById(id);
a.style.display=(a.style.display!="none")?"none":"block";
}
}
for(var i=0;i<9;i++) //number of folders HERE
{
switchDIV('f'+i);
}
// -->
</SCRIPT>

Each time I get a different error

Error: Object required

which points to this line:

a.style.display=(a.style.display!="none")?"none":"block";

I have no jscript experience, just some vbscript. I'm attempting to use
an open source application so I'm getting a crash course on PHP and now
jscript. unfortunately since it's open source software it's difficult
to get the authors to respond to this issue.

thank you
PS
 
M

Manifest Interactive

Shanimal said:
Peter-

I've tried both variations on this:

<script type="text/javascript">
<!--
function switchUl(id){
if(document.getElementById){
a=document.getElementById(id);
a.style.display=(a.style.display!="none")?"none":"block";
}
}
for(var i=0;i<9;i++) //number of folders HERE
{
switchUI('f'+i);
}
// -->
</SCRIPT>

and I also tried this:

<script type="text/javascript">
<!--
function switchDIV(id){
if(document.getElementById){
a=document.getElementById(id);
a.style.display=(a.style.display!="none")?"none":"block";
}
}
for(var i=0;i<9;i++) //number of folders HERE
{
switchDIV('f'+i);
}
// -->
</SCRIPT>

Each time I get a different error

Error: Object required

which points to this line:

a.style.display=(a.style.display!="none")?"none":"block";

I have no jscript experience, just some vbscript. I'm attempting to use
an open source application so I'm getting a crash course on PHP and now
jscript. unfortunately since it's open source software it's difficult
to get the authors to respond to this issue.

thank you
PS

Greetings,

I think you might be loading your function before your divisions are
actually rendered by your browser. This would cause the error that you
are having. If your code instructs the browser to hide a division
before it is rendered it yells at you. On firefox you would not get any
errors unless you looked at the javascript console.

Here is a version of your code that I tested in Firefox and IE and it
runs fine:

<div id="f0">0</div>
<div id="f1">1</div>
<div id="f2">2</div>
<div id="f3">3</div>
<div id="f4">4</div>
<div id="f5">5</div>
<div id="f6">6</div>
<div id="f7">7</div>
<div id="f8">8</div>

<script type="text/javascript">
function switchDIV(id){
if(document.getElementById){
a = document.getElementById(id);
a.style.display=(a.style.display!="none")?"none":"block";
}
}
for(var i=0;i<9;i++){
switchDIV('f'+i);
}
</SCRIPT>

Notice that the script comes after the DIV tags. This way the code will
run without any errors. Anotherway you could use this code is to place
the following code in your head tag:

<HEAD>
<script type="text/javascript">
function switchDIV(id){
if(document.getElementById){
a = document.getElementById(id);
a.style.display=(a.style.display!="none")?"none":"block";
}
}
function toggleDivs(){
for(var i=0;i<9;i++){
switchDIV('f'+i);
}
}
</SCRIPT>
</HEAD>

And this in your body:

<BODY>
<div id="f0">0</div>
<div id="f1">1</div>
<div id="f2">2</div>
<div id="f3">3</div>
<div id="f4">4</div>
<div id="f5">5</div>
<div id="f6">6</div>
<div id="f7">7</div>
<div id="f8">8</div>
<input type="button" value="Toggle" onClick="toggleDivs()">
</BODY>

This will allow you to have abutton that toggles the divs off and on.

Tested it and it works great.

I posted the script on my server here if you wanted to download the
code without it getting broken up like it can sometimes on these sites:

http://www.manifestinteractive.com/usenet/toggle_div.html

Hope this helps,
- Peter Schmalfeldt
 

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,774
Messages
2,569,600
Members
45,179
Latest member
pkhumanis73
Top