Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6784067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:56:42+00:00 2026-05-26T16:56:42+00:00

I have a simple script that should cause one of three divs to be

  • 0

I have a simple script that should cause one of three divs to be visible while the other two are not. The function that does the work is called like so:

onchange="switch(this);"

Firebug indicates that there is an error with this text:

Javascript Error: missing { before switch body

The erroneous code it indicates is line one of my .php file where the doctype is defined like so:

<!doctype html>

The funny thing here is that I have another page with the same doctype and a script that is virtually identical which works 100%. The only differences between the two pages are that in the one that does work, I call the script from

One more thing about the Firebug output: On the page that works, the firebug script window shows the javascript like so:

function onclick(event) {
    switch(this);
}

Now, on the page where the script doesn’t work, Firebug shows no output that has anything to do with onchange, onclick, or anything else. It just shows the code from my javascript file and tells me I am missing the opening bracket to the function when it is clear as day that it’s there. Perhaps, even with the script in the head of my main php file, something odd is happening with scope, making the defined function invisible to the callers. Any ideas?

1: why would Firebug tell me the error is on line 1 where the doctype is defined when the function that fails isn’t even in the same file?

2: Does the doctype effect the way that javascript runs, and how do I debug it if it does?

I would prefer to continue using only HTML5 for this project and use a javascript file for backwards compatibility. Any help is very welcome!

P.S. I am running Ubuntu 11.10 with Apache2, PostgreSQL, and PHP5. Everything works perfectly outside of this one javascript issue.

EDIT: Totally stupid question, but I guess these things happen sometimes. As stated in the answers, switch is a keyword in Javascript and changing the name of my function fixed the problem. I really should have noticed that since my editor highlights keywords in brown…

I am not deleting this post (unless someone else suggests I do) in case someone else out there runs into the same problem. I am giving the answer to the guy who answered it first because his answer also explained the reason why I was getting the error messages I was getting, which is probably more helpful in the long run than a simple awareness of switch statements.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:56:43+00:00Added an answer on May 26, 2026 at 4:56 pm

    This error has nothing to do with your doctype or HTML5. It occurs because switch is a reserved word used for switch statements; you cannot name a function switch.

    So when you do switch(this) the JavaScript engine is expecting you to follow that up with the rest of the switch statement, including the opening {, the switch body, and then the closing }. When you don’t do that, it throws the given error.

    The error is on “line 1” because you used an inline event handler, which in Firebug’s mind is a JavaScript file with one line—that line simply being switch(this);. Firebug does not deal in line numbers of HTML files, only those of JavaScript files—whether they be real JavaScript files, or “virtual” ones generated by inline event handlers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple python script that should scan a text file, which
I have a simple script that does some search and replace. This is basically
I have a simple Python script that I want to stop executing if a
I have a simple PowerShell script that uses WMI to create a web site
I have a simple bat script that copies files from an known directory to
I have a simple Python script that uses the socket module to send a
I have a simple PHP script that will either serve up a streaming ASF
I have a very simple greasemonkey script that I want to call an already
I have a very simple bit of script that changes the status of an
I have the following simple python test script that uses Suds to call a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.