/    Sign up×
Community /Pin to ProfileBookmark

Syntax Error Unexpected token }

Alright, I am running into an error I just can’t run down here, maybe a fresh, experienced set of eye can help me out and tell me what is going on. If I comment out the function change(a) there is no issue, but when it is not chrome, ie, and firefox all throw up on me with the error in the title, I put the code through Lint and there are no errors, help me if you can pls. Here is a straight copy and paste from my js, this error is happening in line 1 of my page. Any help is greatly appreciated.

[CODE]

function JSClock()
{

var timeOut, now, time, app, hour, min, sec, ampm, size;

now = new Date();

hour = now.getHours(now.setHours(now.getHours() + 14));

ampm = (hour >= 12) ? ‘ P.M.’ : ‘ A.M.’;

if (hour > 12) { hour = hour – 12; }

if (hour < 10) { hour = ‘ ‘ + hour; }

min = now.getMinutes();

if (min < 10) { min = ‘0’ + min; }

sec = now.getSeconds();

if (sec < 10) { sec = ‘0’ + sec; }

time = hour + ‘:’ + min + ‘:’ + sec + ampm;

document.getElementById(“time”).innerText = time;

timeOut = setTimeout(‘JSClock()’, 1000);

}

function LoadImages(){

var a;
a = new Image();
a.src = “images/obattle.jpg”;
a = new Image();
a.src = “images/obio.jpg”;
a = new Image();
a.src = “images/ocart.jpg”;
a = new Image();
a.src = “images/ofinancials.jpg”;
a = new Image();
a.src = “images/ologout.jpg”;
a = new Image();
a.src = “images/oadmin.jpg”;
a = new Image();
a.src = “images/ohtc.jpg”;
a = new Image();
a.src = “images/omisc.jpg”;
a = new Image();
a.src = “images/oaddstats.jpg”;
a = new Image();
a.src = “images/oattacks.jpg”;
a = new Image();
a.src = “images/oraces.jpg”;
a = new Image();
a.src = “images/orats.jpg”;
a = new Image();
a.src = “images/osnews.jpg”;

}

function change(a){
b = document.getElementById(a).src;
switch (b){

case “images/y.jpg”:
document.getElementById(a).src = “images/r.jpg”;
break;
case “images/g.jpg”:
document.getElementById(a).src = “images/y.jpg”;
break;
case “images/r.jpg”:
document.getElementById(a).src = “images/g.jpg”;
break;
default:
break;
}
}

/*
function ichange(a){
b = document.getElementById(a).src;
if (b = “images/y.jpg”)
{
document.getElementById(a).src = “images/r.jpg”;
}
if (b = “images/g.jpg”)
{
document.getElementById(a).src = “images/y.jpg”;
}
if (b = “images/r.jpg”)
{
document.getElementById(a).src = “images/g.jpg”;
}
}

*/
[/CODE]

to post a comment
JavaScript

16 Comments(s)

Copy linkTweet thisAlerts:
@CaptainSessaJun 19.2012 — 1.) Where and how do you call the function.

2.) Is this everything? When you comment function "change(a)" without making changes to the HTML / XML, you should still see an error with "function change(a) is not defined".

The function itself is ok as far as I can see.
Copy linkTweet thisAlerts:
@burnmeauthorJun 19.2012 — Thanx for looking,

I call the function like so: repeatedly in a table with cells that look like this:

[code=html]<td><a href='javascript:void(0)' onclick=""ichange(""b11"");""'><img id='b11' src='images/y.jpg'></a></td>[/code]

That is everything in my script file, refed like so:

[code=html]<script src='scripts.js' language='Javascript' type='text/javascript'></script>[/code]

As for commenting out, I worked last night, and when I commented out the change(a) it would say change(a) is not defined, as well for jsclock and loadimages respectively. NOW, I attempted to comment each out function out and it doesn't matter, I still get the same error. So it does lead me to believe it lies somewhere else, but I use no other javascript, none, not in a straight script tag, or in another js file, so I am even more stumped. And just to give you as much info as possible, I am using this in an asp file, but the output of the file is perfect, so IDK.
Copy linkTweet thisAlerts:
@burnmeauthorJun 19.2012 — sorry just noticed I used the ichange in this example, but I did you change(a) in the code, but I can't edit the post, or I would.
Copy linkTweet thisAlerts:
@PadonakJun 19.2012 — if (b = "images/y.jpg") how can this statement work?!
Copy linkTweet thisAlerts:
@CaptainSessaJun 19.2012 — What the heck are you doing with all those quotes?

Try calling the func like this:

onclick='ichange("b11");'

Also, why use letters AND integers for cell id's, since a - z can be replaced by letters themselves.. you would not have to worry about quotes, and working with ints is always faster than with strings

*edit*

@padonak: If you read again, he says he got problems with the change() function, not ichange().. the fact that ichange wont work is something different and ichange is commented ?
Copy linkTweet thisAlerts:
@burnmeauthorJun 19.2012 — well it does not, hence the reason that portion is commented out. The return when you debug is the entire path, including the domain and such, so I will have to work that out, but it isn't calling the function in the first place, even with the removal of the ichange function completely it still errors out on line 1 char 2, which no matter the file, is either the letter 'u' in function, or the letter 'H' in head, depending on which file you are looking at i.e. the main page or the js file.
Copy linkTweet thisAlerts:
@burnmeauthorJun 19.2012 — well the quotes are because the calls are being made with the insertion based on an asp file, so when you write calls you have to double quote the main part, and single quote the args to make it come out right in the response.
Copy linkTweet thisAlerts:
@PadonakJun 19.2012 — [CODE]onclick=""ichange(""b11"");""'[/CODE]

too many quotes isn't it?

sorry for duplicating ))
Copy linkTweet thisAlerts:
@CaptainSessaJun 19.2012 — Is the thing on a webserver somewhere? If yes link please, I'd like to take a look at it with firebug ?
Copy linkTweet thisAlerts:
@burnmeauthorJun 19.2012 — yes, but I have removed the single quote on the end with no avail. Hehe, this is the hardest part of asking for help, sometime it helps to be there, but I do appreciate the time you all take to look much appreciated.
Copy linkTweet thisAlerts:
@burnmeauthorJun 19.2012 — captain may I pm you a link, uname, and pass?
Copy linkTweet thisAlerts:
@CaptainSessaJun 19.2012 — sure thing u can ?
Copy linkTweet thisAlerts:
@CaptainSessaJun 19.2012 — Ok, so here is how your link is interpreted:

<a b31");"="" onclick="change(" href="javascript:void(0)">

That's the content of one of your table cells, which basically means you screwed the quotes up as I thought.

And that's what firebug tells me, I do not even see your error message:

Timestamp: 19.06.2012 20:30:55

Error: syntax error

Source: whappa

Line: 1, col: 7

Source:

change([/QUOTE]


So maybe you fix the quoting prob first, otherwise I don't even get to your error message ?
Copy linkTweet thisAlerts:
@burnmeauthorJun 19.2012 — alrighty, well, I do appreciate you taking a look, I will scorch my eyes trying to find the error. This is killing me, chromes error reports are a joke, and apparently ie as well. You spent too much time trying, I can't thank you enough. Also, if someone has the ability I would appreciate my link taken out, but no biggie, thanks a ton.
Copy linkTweet thisAlerts:
@CaptainSessaJun 19.2012 — Your function is working:

>>> change("test")

TypeError: document.getElementById(a) is null

b = document.getElementById(a).src;[/QUOTE]


=> Does not find an id with "test".

>>> change("b22");

undefined[/QUOTE]


Function runs through without errors..

Really seems to be quoting only ?

Oh, and on pageload I get another error

"onUnload="clearTimeout(timeOut);" in your body tag

the var timeOut has not been defined by you apparently in your html code ?

*edit*

Sorry, I took the url away ?
Copy linkTweet thisAlerts:
@burnmeauthorJun 19.2012 — ah, thanks for the heads up on that, the var should be global, not in the function. Thanks again tho, my brain has just iced over with this one. There are more quotes in my files then a newspaper.
×

Success!

Help @burnme spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...