JavaScript for GridView row TemplateFields
<p>I'm creating a program where, in each GridView row, there is a checkbox and a textbox, which are unchecked and disabled by default respectively. When the checkbox is ticked, I need to fire a bit of JavaScript to enable that textbox, and vice versa for when is unticked. So far I am doing this:</p>

<p>JS:</p>

<pre><code>    &lt;script type="text/javascript"&gt;
    function onholdev(index) {
        var chk = document.getElementById('&lt;%=grdCons.Rows[index].FindControl("chkHold").ClientID %&gt;');
        var txt = document.getElementById('&lt;%=grdCons.Rows[index].FindControl("txtReason").ClientID %&gt;');

        if (chk.checked == true) {
            txt.disabled = false;
        }
        else {
            txt.disabled = true;
            txt.value = "";
        }
    }
&lt;/script&gt;
</code></pre>

<p>C# (RowDataBound event)</p>

<pre><code>            CheckBox chkHold = ((CheckBox)e.Row.FindControl("chkHold"));
        chkHold.Attributes.Add("onchange", "onholdev(" + e.Row.RowIndex + ")");
</code></pre>

<p>But in the JS, it's saying the 'index' variable does not exist, in the first line of the function (that begins with var chk). Am I doing this right?</p>
