Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to enable/disable a certain textbox depending on which radiobutton was checked?
    primarykey
    data
    text
    <p>I've 3 radiobuttons and a textbox next to each other (also 3 text boxes) like this:</p> <pre><code>&lt;input type = "radio" id = "myRadio" value = "A" checked = "checked"/&gt; &lt;input type = "text" id = "myText1"/&gt; &lt;br/&gt; &lt;input type = "radio" id = "myRadio" value = "B" /&gt; &lt;input type = "text" id = "myText2"/&gt;&lt;br/&gt; &lt;input type = "radio" id = "myRadio" value = "C" /&gt; &lt;input type = "text" id = "myText2"/&gt; </code></pre> <p>The first radioButton is <strong>checked</strong> by default, and the textbox next to it should be <strong>enabled</strong>. the 2 other radiobuttons are <strong>not checked</strong>, and the textbox next to them should be <strong>disabled</strong>. </p> <p>I need a Jquery script so that:</p> <ol> <li>when a radiobutton is checked, the textbox next to it should be enabled</li> <li>the textboxes next to the radiobutton unchecked remain disabled</li> </ol> <p>In other words, only the textbox next to a radiobutton that's checked is enabled. </p> <p><strong>Personally, I have difficult writing the script because all the radiobutton have the same id.</strong> </p> <p>I've tried this, but I'm getting all 2 radiobuttons checked at the same time while only the first textbox remains enabled.</p> <pre><code>$(":text").attr("disabled", "disabled"); if($(":radio").attr("checked")) { $(":radio:checked + :text").removeAttr("disabled", "disabled"); }; </code></pre> <p><strong>EDIT</strong></p> <p>Look at the code above. When the page loads for the first time, the first radiobutton (whose <strong>value = "A"</strong>) is checked, so the textbox next to it (whose <strong>id = "myText1"</strong>) should be enabled. When user clicks a different radiobutton, for instance the one with a <strong>value = "B"</strong>, the textbox next to it (whose <strong>id = "myText2"</strong>) should be enabled, and so on. </p> <p>I hope I have been more explicit this time.</p> <p>By the way, I'm using ASP.NET MVC.</p> <p>Thanks for helping</p>
    singulars
    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