Uncaught SyntaxError: Unexpected token ,

roblickley
roblickley used Ask the Experts™
on
Can anyone tell me why this is causing an Uncaught SyntaxError: Unexpected token , error

I use this kind of function all the time but with numbers only - of course it relates to text but I just can not work out the correct " or ' to get this information to pass to my js function.

<a class="btn btn-primary btn-lg hidden-print" onclick="recordTB(52584,1,'Preliminary 7 2002',12/11/2017)" role="button"> Print &amp; Record</a>

Open in new window


Thank you
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I should say that I have also tried it without any "  or ' and it equally doesn't work.
The text as is works perfectly for me.
Just created a random function with that signature, but no issues.

Can you post the JS function?
And you're getting this error in the browser (which one) or the IDE?
Also note, you should wrap the date at the end in quotes as well, otherwise the browser will just divide the numbers.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
I am guessing this
<a class="btn btn-primary btn-lg hidden-print" onclick="recordTB(52584,1,'Preliminary 7 2002','12/11/2017')" role="button"> Print &amp; Record</a>

Open in new window

i.e. enclose the date in single quotes.
As I suggested directly above ;)

But that still should not be the cause of the problem, as it's a perfectly valid mathematical expression (though obviously not what he's after), and all the commas flagging the token error come before that.
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
@Snarf0001 - so you did - looked for a code block and did not find one so threw my 10c in.

I am guessing the syntax error is actually referring to something else - not that line. Maybe in the function itself.

Can we see a link?

Or at least more of the code?
Or similarly, if this happens to be rendered out with server code (the one you provided just being a sample), and you're writing out a full date in a different format, then the missing quotes IS quite likely the problem.

As you could end up with "Jan 1, 2012" for example.

As per Julian, we need a bigger picture.

Author

Commented:
Thank you all!
I wrapped the date in ' and it worked.
I did this before but it didn't work  - no idea why but it does not.
onclick="recordTB(52556,'YLHZDFK','Preliminary 1 2006','12/11/2017')"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial