473,569 Members | 3,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onclick code not working. Browser's error: object expected lines 11, 12, 13

18 New Member
I could about swear this was working perfectly while I was adding some other functionality somewhere else. I now removed that functionality and it doesn't work. If someone could find what I broke, please tell me. I am new to using JavaScript seriously (probably been tweaking individual lines of code for 5 years) and after staring at my mistake for hours I probably can no longer see it.

Intended functionality: 3 links that can be clicked to display a different div tag.

I'm testing with Win XP Prof SP2, IE7, English. Later I'll be on a PC that has a slew of other browsers loaded, but I think it's my own ignorance--not IE7's.

HTML:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>URL.NET</title>
  4. <link rel="stylesheet" type="text/css" href="homestyle.css" />
  5. <script src="section.js"></script>
  6. </head>
  7.  
  8. <body>
  9.  
  10. <div id="menuWrapper">
  11.     <div id="home" class="menuButton" onclick="activateSection('home');">Home</div><div class="menuSpacer"></div>
  12.     <div id="visitme" class="menuButton" onclick="activateSection('visitme');">Visit Me!</div><div class="menuSpacer"></div>
  13.     <div id="contactme" class="menuButton" onclick="activateSection('contactme');">Contact Me</div>
  14. </div>
  15.  
  16. <div id="contentWrapper">
  17.     <div id="homeTab" class="tabContent">Go Home</div> 
  18.     <div id="visitmeTab" class="tabContent">Visit Me</div> 
  19.     <div id="contactmeTab" class="tabContent">Contact Me: <a href="mailto:me@gmail.com">me@gmail.com</a></div>
  20.     <div id="errorTab" class="tabContent">Something Isn't working.</div>
  21. </div>
  22.  
  23. </body>
  24. </html>
  25.  
my script:
Expand|Select|Wrap|Line Numbers
  1. function activateSection(section)
  2. {
  3.     var home = document.getElementById("homeTab");
  4.     var visitme = document.getElementById("visitmeTab");
  5.     var contactme = document.getElementById("contactmeTab");
  6.     var error = document.getElementById("errorTab");
  7.  
  8.     if (section == 'home') 
  9.     {
  10.         home.style.display="block";
  11.         visitme.style.display="none";
  12.         contactme.style.display="none";
  13.         error.style.display="none";
  14.     }
  15.     else if (section == 'visitme') 
  16.     {
  17.         home.style.display="none";
  18.         visitme.style.display="block";
  19.         contactme.style.display="none";
  20.         error.style.display="none";
  21.     else if (section == 'contactme') 
  22.     {
  23.         home.style.display="none";
  24.         visitme.style.display="none";
  25.         contactme.style.display="block";
  26.         error.style.display="none";
  27.     }
  28.     else
  29.     {
  30.         home.style.display="none";
  31.         visitme.style.display="none";
  32.         contactme.style.display="none";
  33.         error.style.display="block";
  34.     }
  35. }
  36.  
I don't think you need to see my CSS, but it should be CSS2 standards-compliant and includes an htc fix for explorer to make IE 5 through 7 do what it should do with hover pseudo-classes if IE where standards compliant.

Many thanks!
Sep 25 '07 #1
3 8392
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN!

On the third 'else' between lines 20 and 21, you have a closing bracket missing.
Sep 25 '07 #2
Danigan
18 New Member
I would donate my life to the hatred of bracket and semi-colon related errors but... I did that many years ago when I learned my first language.

Many thanks indeed. I will frequent these forums so that I may learn and give back the time and knowledge I take.
Sep 25 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Glad to hear you got it working. A good idea would be to check the error console of a browser that gives you better error messages.
Sep 25 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

53
5674
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
0
1581
by: malcolm | last post by:
How do I get a web-browser loaded with on-the-fly content and a JavaScript onclick popup function to work? I've embedded an axWebBrowser in my (vb.net) application. The browser starts with about:blank, and then I set AxWebBrowser1.Document.Body.innerHTML to the desired HTML. The HTML contains a link (which works fine) and a Javascript...
4
1949
by: Roland | last post by:
I was wondering, what happens when you have an onclick event and an error occurs in it: In an <a> element: onclick="zoomFullExtent(); return false;" I know that there is an error happening in zoomFullExtent. I didn't define my own error handler, so the default one is used.(My browser is Firefox 1.0).
53
81680
by: usenet | last post by:
See <ul> <li><a name="link1" onClick="alert(this.name);return false;" href="#">Link1</a></li> <li><a name="link2" href="javascript:alert(this);">Link2</a></li> <li>Item 3</li> </ul> Clicking on the first list item gives me "link1" because "this" refers
5
2574
by: moondaddy | last post by:
I have a <a> element in a datagrid which wraps some asp.net labels. this element also has an onclick event which does not fire in netscape 6 (and perhaps other browsers for all I know...). Below is the code for this. the onclick event calls a javascript function which I put an alert in the firt line to tell me if its working. It does work...
5
1140
by: Joe Simmonds | last post by:
Hi All, I have just had a problem with some VB.net, I wonder if anybody can shed a little light and ease my confused brain. The problem is resolved now but I can't work out what happened and, more importantly, I can't guarantee it won't happen again. Have I misunderstood the situation? Can anybody help? An error was spotted in a running...
5
2095
by: Fred.Grieco | last post by:
Hi every body, I have a little pb and I'm turning around : function MyFCTN(var1,var2) { var mytable = document.getElementById("myTBL"); for (var i=myTBL.childNodes.length-1; i>0; i--){ myTBL.removeChild(myTBL.childNodes); } for(var i=0; i<var1.length; i++){
4
5790
by: phil | last post by:
Hi, I defined a Html button but added the option 'runat="server" ' like this: <form id="form1" runat="server"> <input id="Button1" type="button" value="button" runat="server" onclick="hfd()" /> </form> <script language="javascript" type="text/javascript"> function hfd() {alert("ok")}
17
2657
by: yawnmoth | last post by:
http://www.frostjedi.com/terra/scripts/demo/this-alert.html http://www.frostjedi.com/terra/scripts/demo/this-alert2.html Why, when you click in the black box, do the alert boxes say different things? Shouldn't they say the same thing?
0
7703
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...
0
7619
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...
1
7681
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...
0
6290
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...
1
5514
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...
0
5228
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...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
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.