reemaaroza
reemaaroza

Reputation: 3

Enable textbox for a radiobuttonlist one of the listitem value using javascript

script for enable/disable

<script type="text/javascript" language="javascript">
    function display() {
     if (document.getElementById("<%=Institution.ClientID %>").value == "others") {
         document.getElementById('<%= lblSpecify.ClientID %>').style.visiblity = "visible";
         document.getElementById('<%= InstituteOthers.ClientID %>').style.visiblity = "visible";
     }
     else {
         document.getElementById('<%= lblSpecify.ClientID %>').style.visiblity = "hidden";
         document.getElementById('<%= InstituteOthers.ClientID %>').style.visiblity = "hidden";
     }

 }

</script>

If 5th listitem(AnyOther) is selected then only label(lblSpecify) and textbox(InstituteOthers) should be visible=true ,otherwise visible=false

Why did you choose our Institution:

1Doctor 2WordofMouth 3Camps 4OldPatients 5AnyOther

  </td>
     <td>
        <asp:Label ID="lblSpecify" runat="server" Text="Specify :" Visible="false"></asp:Label>
    </td>
    <td>
        <asp:TextBox ID="InstituteOthers" runat="server"  TabIndex="18" MaxLength="20" Visible="false"></asp:TextBox>
    </td>

 </tr>
 </table>

But it is not effecting.please help.

i am calling the script in

onchange="display" RepeatDirection="Horizontal" TabIndex="18" >

Upvotes: 0

Views: 1004

Answers (2)

Test User
Test User

Reputation: 53

There is also OnSeletedIndexChanged event exists on radiobuttonlist you can hide and dispaly textboxes on the value selected.

For doing this in javascript try below script

var list = document.getElementById(<%=Institution.ClientID %>);
var inputs = list.getElementsByTagName("input");
 var selected;
 for (var i = 0; i < inputs.length; i++) {
      if (inputs[i].checked) {
          selected = inputs[i];
          break;
       }
  }
  if (selected.value == "others") {
       document.getElementById('<%= lblSpecify.ClientID %>').style.visiblity =   "visible";
       document.getElementById('<%= InstituteOthers.ClientID %>').style.visiblity = "visible";
  }

Upvotes: 1

Test User
Test User

Reputation: 53

Can you give the where you are calling display method.

If there is dropdown list on your page you can do this on selectedindex change event.

Upvotes: 0

Related Questions