The Javascript function does not work for the list of radio buttons

advertisements

I have a javascript function wherein based on selection I have to enable a row and disable a button on the same page. Earlier it was handled via code behind and was working fine with the same logic. Now it does not work.

JS function:

function ValidateRadioButtonList()
{
   var RBL = document.getElementById('<%=rbListExamShot.ClientID%>');
   var radiobuttonlist = RBL.getElementsByTagName("input");
   var counter = 0;
   var atLeast = 1
   for (var i = 0; i < radiobuttonlist.length; i++) {
   if (radiobuttonlist[i].checked) {

   counter++;
   var selected = i;
   }
   }
   if (atLeast = counter) {
   // return arguments.IsValid;
   var RowMessage = document.getElementById  ('<%                               =RowCliamMessage.ClientID%>');
   RowMessage.style.display = "block";
   }
   else {

   RowMessage.style.display = "none";
   }
   if (selected == 1) {

   var Submit = document.getElementById('<%=Save.ClientID%>');
   Submit.disabled = true;
   return false;
   }
   else {
   return true;
   }
 }

asp.net control and validator:

   <td  align="left">
            <asp:RadioButtonList CssClass="label" ID="rbListExamShot" runat="server" AutoPostBack="true"
                RepeatDirection="Horizontal" ValidationGroup="Save"
                onselectedindexchanged="rbListExamShot_SelectedIndexChanged">
                <asp:ListItem Text="Single Shot" Value="1"></asp:ListItem>
                <asp:ListItem Text="Double Shot" Value="2"></asp:ListItem>
            </asp:RadioButtonList>
            </td>
            <td>
              <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Text="Please select voucher type"
                Display="Dynamic" ControlToValidate="rbListExamShot" ValidationGroup="Save"
                ForeColor="Red" Font-Bold="False"></asp:RequiredFieldValidator>
                 <asp:CustomValidator ID="CustomValidator1" runat="server" ValidationGroup="Save"
                Display="Dynamic" ErrorMessage=".Double Shot Vouchers cannot be reimbursed."
                ControlToValidate="rbListExamShot" ClientValidationFunction="ValidateRadioButtonList"
                ForeColor="Red" Font-Bold="False"></asp:CustomValidator>
        </td>


thanks everyone for their comments..the problem was that I was getting the client Id in var and then trying to set properties..now I am doing something like: document.getElementById('<%=Save.ClientID%>').disabled = true..and it is working for me!thanks all