Sending variables in Javascript

inside a function, I have code that generates html that includes a javascript function that sends a variable to another function.

It looks like this:

searchVidResult += '<div class="triovid lastvid"><a href="#" onclick="swapvids('+ finalID +');">....

Open in new window


The issue is, the finalID variable (a string) isn't being quoted correctly, so i get an syntax error or an undefined object error.
how do I get finalID sent to sawpvids?

Thanks for your help!
LVL 1
slightlyoffAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hankknightCommented:
Where in your code does it say:
var finalID

Open in new window

?
Remove "var " and then add this to the very top above all other JavaScript code:
var finalID;

Open in new window

0
Dave BaldwinFixer of ProblemsCommented:
Your example is missing a final single quote.  In addition, you may need quotes around '+ finalID +' but you have already used both single and double quotes.  I'm not sure how to resolve that.
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
besides missing the final quote as others pointed out, you need to escape the single quote inside your swapvids() function. to do that, you would use

\' - ex: alert(top O\' the mornin\' to ya!');

so in your code, it should be:

searchVidResult += '<div class="triovid lastvid"><a href="#" onclick="swapvids( \' '+ finalID +' \');">....

Open in new window


i put spaces in between the quotes for readability.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.