Solved

syntax error in javascript file

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

821 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