Solved

syntax error in javascript file

Posted on 2011-03-12
5
371 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now