Note that there are some explanatory texts on larger screens.

plurals
  1. POHide/Show @Html.TextBoxFor
    text
    copied!<p>I have the following code where I am showing a Name, Surname, checkbox and textbox :-</p> <pre><code> &lt;td&gt; @for (var i = 0; i &lt; Model.checkBoxListTeamA.Count();i++ ) { &lt;div class="ScorerCheckboxList"&gt; @Html.HiddenFor(it =&gt; it.checkBoxListTeamA[i].PlayerId) @Html.Label(Model.checkBoxListTeamA[i].PlayerName) @Html.Label(Model.checkBoxListTeamA[i].PlayerSurname) @Html.CheckBoxFor(it =&gt; it.checkBoxListTeamA[i].Checked, new { id="CheckBoxA" }) @Html.TextBoxFor(it =&gt; it.checkBoxListTeamA[i].NoOfGoals, new { id="TextBoxA", style="width:20px;" }) &lt;/div&gt; &lt;br/&gt; } &lt;/td&gt; </code></pre> <p>I also have the following Jquery script :-</p> <pre><code>&lt;script type='text/javascript'&gt; $(document).ready(function () { ShowHideTextBox(); $('#CheckBoxA').click(function (event) { alert('clicked'); ShowHideTextBox(); }); }); function ShowHideTextBox() { if ($('#CheckBoxA').is(':checked')) { $('#TextBoxA').attr('visible', true); } else { $('#TextBoxA').removeAttr('visible'); } } &lt;/script&gt; </code></pre> <p>However I am not achieving what I want, ie when the user clicks on a checkbox, I want to display the textbox, and if the checkbox is unticked, then I want to hide the checkbox.</p> <p>What is wrong with my script? I am not even getting the click when the checkbox is checked!</p> <p>Thanks for your help and time</p> <p>----------------UPDATE JQUERY--------------------------</p> <pre><code>&lt;script type='text/javascript'&gt; $(document).ready(function () { ShowHideTextBox(); }); function ShowHideTextBox() { $('.ScorerCheckboxList :checkbox').click(function () { alert('Checked!'); $(this).siblings('input[type="text"]').toggle(this.checked); }); } &lt;/script&gt; </code></pre>
 

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