Solved

syntax error in javascript file

Posted on 2011-03-12
5
375 Views
Last Modified: 2012-05-11
I have this code in a js file and it keeps coming back syntax error line 3.  Can someone tell me why

function ShowTable(i)
{
    if (i == 1)
     {
         document.getElementById("TableAdd").style.display = "block" ;
     }

}
0
Comment
Question by:mgmhicks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 35117019
If 'i' is valid, that code works fine in IE8 and Firefox.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 35118045
If "i" is not a number (or something that evaluates to a number) you might get an error.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 35118061
//
function ShowTable(i) {
    i = (i || 1); // If "i" is undefined, give it a value
    
    if (i == 1) {
         document.getElementById("TableAdd").style.display = "block" ;
     }
}
//

Open in new window

0
 

Author Comment

by:mgmhicks
ID: 35118143
I believe my problem is that I am using a master file with my page, and that resides in root.  The page that runs the script is in a folder below that.  Once I moved the js file to that folder it stopped erroring.  

I would like the js file to be accessable no matter what folder I am in.  any ideas.  Here is the code in the master file.
<script type="text/javascript" src="eSiteCompanion.js">
</script
0
 
LVL 29

Accepted Solution

by:
Badotz earned 250 total points
ID: 35118174
Without a directory in the src attribute, the browser will look in the same folder in which the page resides.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question