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