Enabling Radiobuttonlist in Javascript

  • Thread starter Thread starter KA Kueh
  • Start date Start date
K

KA Kueh

Dear all,

I am trying to enable the radiobuttonlist which is initally disabled via
javascript and could not get it to work. But if the radiobuttonlist is not
disabled initially then the javascript will work. Is this a feature by
design? What is the best way around this issue? Thanks.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestForm1.aspx.cs"
Inherits="TestForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

<script type="text/javascript">

function test()

{


if (document.getElementById('RadioButtonList1_0').checked)

document.getElementById('RadioButtonXX').disabled=false;

else

document.getElementById('RadioButtonXX').disabled=true;

}

</script>

</head>

<body>

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server" >

</asp:ScriptManager>

<div>

<asp:button ID="btnDelete" runat="server" onClientClick="return confirm('Are
you sure you want to delete this mailbox?')" Text="Delete" />

<asp:RadioButtonList ID="RadioButtonList1" runat="server" >

<asp:ListItem>Apple</asp:ListItem>

<asp:ListItem>Orange</asp:ListItem>

</asp:RadioButtonList>

<asp:CustomValidator ID="CustomValidator1" runat="server"
ClientValidationFunction="test"

ControlToValidate="RadioButtonList1">

</asp:CustomValidator>

<asp:DropDownList ID="DropDownList1" runat="server">

<asp:ListItem Text="One" Value="1"></asp:ListItem>

<asp:ListItem Text="Two" Value="2"></asp:ListItem>

</asp:DropDownList>

<asp:RadioButtonList ID="RadioButtonXX" Enabled="false" runat="server" >

<asp:ListItem>Car</asp:ListItem>

<asp:ListItem>Lorry</asp:ListItem>

</asp:RadioButtonList >

</div>


</form>


</body>

</html>
 
Hi Nick,

Not true. If the radiobuttonlist was initially disabled then the
javascript will not work even if I loop through the radiobutton. What I
want to know is, Is the behaviour as per design or otherwise? Thanks.

Regards.
Kueh
 
this works

<form>
<input type="radio" name="x" disabled><br>
<input type="radio" name="x" disabled><br>
</form>

<script type="text/javascript">
onload=function(){
var radios=document.forms[0].x
for(var i=0;i<radios.length;i++){
radios.disabled=false
}
}
</script>

it will enable them again on page load. that is JAVASCRIPT
talking about asp.net, it may still "remember" that the radios are
disabled, so that i "may" refuse any posting of the radiolist
 
Hi Nick,

Great. I will try your suggested solution.

Regards,
Kueh.

Nick Chan said:
this works

<form>
<input type="radio" name="x" disabled><br>
<input type="radio" name="x" disabled><br>
</form>

<script type="text/javascript">
onload=function(){
var radios=document.forms[0].x
for(var i=0;i<radios.length;i++){
radios.disabled=false
}
}
</script>

it will enable them again on page load. that is JAVASCRIPT
talking about asp.net, it may still "remember" that the radios are
disabled, so that i "may" refuse any posting of the radiolist

Hi Nick,

Not true. If the radiobuttonlist was initially disabled then the
javascript will not work even if I loop through the radiobutton. What I
want to know is, Is the behaviour as per design or otherwise? Thanks.

Regards.
Kueh



















- Show quoted text -
 
Back
Top