0

I am echoing some data from the PHP side along with a tag and here is the code

 echo '<a class="ui label" onclick="variant_desc('.$product_id.');"> '.$variant->Field1.' </a>';

Now the function that I have mentioned within the tag, when I click it throws me the

Uncaught SyntaxError: missing ) after argument list

error... BUT WHY? Where am I masking mistake?

Jijo Nair
  • 828
  • 2
  • 11
  • 30
  • how does that PHP code render in HTML? Have you verified `$product_id` and `$variant->Field1` return what you're expecting? – devlin carnate Jul 08 '16 at 17:58
  • yes...in my response section of network tab in inspect element...it showing me the whole tag..the html tag is also displayed on the page...if I remove the id, the function is also called. only part is there is some error with concatenation ..and I dont knw what is that – Jijo Nair Jul 08 '16 at 18:01

1 Answers1

0

I believe that it's caused of nested quotations. Try this instead:

echo '<a class=\"ui label\" onclick=\"variant_desc(\'.$product_id.\');\"> \'.$variant->Field1.\' </a>';
flott
  • 231
  • 1
  • 11