How to quote a string dynamically in Javascript?
<p>This kinda funny, i want to quote a string value for a function but javascript throws this error <code>Uncaught SyntaxError: Unexpected token }</code></p>

<p>This my code</p>

<pre><code>var val = "Testing String";
var table_row = "&lt;tr&gt;&lt;td&gt;&lt;a href='#' onclick='test('"+val+"')'&gt;Row1&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;";

function test( val ){
  alert( val );
}
</code></pre>

<p>The table row get created fine with the test function bound well with onClick event.
But when i click on the created link i get</p>

<pre><code>`Uncaught SyntaxError: Unexpected token }
</code></pre>

<p>The Value within the test function should be a quoted string.</p>

<p>Note: If i remove the concatenation of the val string, and pass is as a string like this </p>

<pre><code>table_row = "&lt;tr&gt;&lt;td&gt;&lt;a href='#' onClick='test(\"Testing String\")' &gt;Row1&lt;/a&gt;&lt;/td&gt;";
</code></pre>

<p>... it works</p>

<p>Where am i goofing?</p>

<p>Gath.</p>
