<p>How do I delimit a Javascript data-bound string parameter in an anchor <code>OnClick</code> event?</p>
<ul>
<li>I have an anchor tag in an ASP.NET Repeater control.</li>
<li>The <code>OnClick</code> event of the anchor contains a call to a Javascript function.</li>
<li>The Javascript function takes a string for its input parameter.</li>
<li>The string parameter is populated with a data-bound value from the Repeater.</li>
</ul>
<p>I need the &quot;double quotes&quot; for the <code>Container.DataItem</code>.<br />
I need the 'single quotes' for the <code>OnClick</code>.</p>
<p>And I still need <em>one more delimiter</em> (triple quotes?) for the input string parameter of the Javascript function call.</p>
<p>Since I can't use 'single quotes' again, how do I ensure the Javascript function knows the input parameter is a string and not an integer?</p>
<p>Without the extra quotes around the input string parameter, the Javascript function thinks I'm passing in an integer.</p>
<p>The anchor:</p>
<pre><code>&lt;a id=&quot;aShowHide&quot; onclick='ToggleDisplay(&lt;%# DataBinder.Eval(Container.DataItem, &quot;JobCode&quot;) %&gt;);' &gt;Show/Hide&lt;/a&gt;    
</code></pre>
<p>And there is my Javascript:</p>
<pre><code>&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;
/* Shows/Hides the Jobs Div */
function ToggleDisplay(jobCode)
{
    /* Each div has its ID set dynamically ('d' plus the JobCode) */
    var elem = document.getElementById('d' + jobCode);

    if (elem) 
    {
        if (elem.style.display != 'block') 
        {
            elem.style.display = 'block';
            elem.style.visibility = 'visible';
        } 
        else
        {
            elem.style.display = 'none';
            elem.style.visibility = 'hidden';
        }
    }
}
&lt;/script&gt;
</code></pre>

[{'answer_id': 1875, 'author': 'Grant', 'author_id': 30, 'author_profile': 'https://Stackoverflow.com/users/30', 'pm_score': 2, 'selected': False, 'text': '<blockquote>\n  <p>Without the extra quotes around the input string parameter, the Javascript function thinks I\'m passing in an integer.</p>\n</blockquote>\n\n<p>Can you do some rudimentary string function to force JavaScript into changing it into a string? Like </p>\n\n<pre><code>value = value + ""\n</code></pre>\n'}, {'answer_id': 1881, 'author': 'Shawn', 'author_id': 26, 'author_profile': 'https://Stackoverflow.com/users/26', 'pm_score': 1, 'selected': False, 'text': '<p>Try putting the extra text inside the server-side script block and concatenating.</p>\n\n<pre><code>onclick=\'&lt;%# "ToggleDisplay(""" &amp;  DataBinder.Eval(Container.DataItem, "JobCode") &amp; """);" %&gt;\'\n</code></pre>\n\n<p>Edit: I\'m pretty sure you could just use double quotes outside the script block as well.</p>\n'}, {'answer_id': 1886, 'author': 'lubos hasko', 'author_id': 275, 'author_profile': 'https://Stackoverflow.com/users/275', 'pm_score': 6, 'selected': True, 'text': '<p>I had recently similar problem and the only way to solve it was to use plain old HTML codes for single (<code>&amp;#39;</code>) and double quotes (<code>&amp;#34;</code>).  </p>\n\n<p>Source code was total mess of course but it worked.</p>\n\n<p>Try</p>\n\n<pre><code>&lt;a id="aShowHide" onclick=\'ToggleDisplay(&amp;#34;&lt;%# DataBinder.Eval(Container.DataItem, "JobCode") %&gt;&amp;#34;);\'&gt;Show/Hide&lt;/a&gt;\n</code></pre>\n\n<p>or</p>\n\n<pre><code>&lt;a id="aShowHide" onclick=\'ToggleDisplay(&amp;#39;&lt;%# DataBinder.Eval(Container.DataItem, "JobCode") %&gt;&amp;#39;);\'&gt;Show/Hide&lt;/a&gt;\n</code></pre>\n'}, {'answer_id': 637033, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Passing variable to function without single quote or double quote</p>\n\n<pre><code>&lt;html&gt;\n    &lt;head&gt;\n    &lt;/head&gt;\n    &lt;body&gt;\n        &lt;script language="javascript"&gt;\n        function hello(id, bu)\n        {\n            alert(id+ bu);\n        }\n        &lt;/script&gt;\n        &lt;a href ="javascript:\n            var x = &amp;#34;12&amp;#34;;\n            var y = &amp;#34;fmo&amp;#34;;\n            hello(x,y)"&gt;test&lt;/a&gt;\n    &lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n'}, {'answer_id': 798480, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<pre><code>onclick=\'javascript:ToggleDisplay("&lt;%# DataBinder.Eval(Container.DataItem, "JobCode")%&gt; "); \'\n</code></pre>\n\n<p>Use like above.</p>\n'}]
['https://Stackoverflow.com/questions/1873', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/242/']