Note that there are some explanatory texts on larger screens.

plurals
  1. POTriple Quotes? How do I delimit a databound Javascript string parameter in ASP.NET?
    primarykey
    data
    text
    <p>How do I delimit a Javascript databound 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 databound value from the Repeater.</li> </ul> <p>I need the "double quotes" 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="aShowHide" onclick='ToggleDisplay(&lt;%# DataBinder.Eval(Container.DataItem, "JobCode") %&gt;);' &gt;Show/Hide&lt;/a&gt; </code></pre> <p>and here is the Javascript:</p> <pre><code>&lt;script language="JavaScript" type="text/javascript"&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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload