Link to home
Start Free TrialLog in
Avatar of slightlyoff
slightlyoff

asked on

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!
Avatar of hankknight
hankknight
Flag of Canada image

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

Avatar of Dave Baldwin
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.
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial