rosiedoon 0 Newbie Poster

Hello all.

I am building a webform and need some validation on radiobuttonlists but I am really stuck and struggling. I need to use a customvalidator with some javascript. I've been working on this for some time and can't get it to work. Help!

The logic goes like this:

  • User selects one of 2 values in radiobuttonlist10, either 1 or 2.
  • If user selects value 1 in radiobuttonlist10, they must continue to radiobuttonlist11.
  • If user selects value 2 in radiobuttonlist10, they must continue to radiobuttonlist20

I want to validate radiobuttonlist11, so that if the user has selected value 1 in radiobuttonlist10 (which means they must enter a value for radiobuttonlist11) and tries to submit the form without entering a value for radiobuttonlist11, they are alerted that they must give a value for radiobuttonlist11. That's it.

What I have so far is this:

radiobuttonlist10:[/B]

<asp:RadioButtonList ID="radiobuttonlist10" runat="server" RepeatDirection="Horizontal">
                <asp:ListItem Value="1" />
                <asp:ListItem Value="2" />
            </asp:RadioButtonList></td>

radiobuttonlist11:

<asp:RadioButtonList ID="radiobuttonlist11" runat="server" RepeatDirection="Horizontal">
                <asp:ListItem Value="1" />
                <asp:ListItem Value="2" />
            </asp:RadioButtonList></td>

My customvalidator:

<asp:CustomValidator ID="radio11validator" runat="server"
    ControlToValidate="radiobuttonlist11" ValidateEmptyText="true"
    ErrorMessage="Please enter a value for question 11"
    ClientValidationFunction="validateMyBtn">
</asp:CustomValidator>

The javascript function called by the customvalidator:

<script type="text/javascript">
  function validateMyBtn(oSrc, args){
      var rbtnValue = null;
      var rbtnList = document.getElementsByName('<%= radiobuttonlist10.ClientID %>');
      var radio = rbtnList[0].getElementsByTagName("input");
      for (var j = 0; j < radio.length; j++) {
         if (radio[j].checked)
             rbtnValue = radio[j].value;
      }
      if (rbtnValue == '1') {
             args.IsValid = !(args.Value == "")
            }
      else {
              args.IsValid = true;
            }
}
</script>

I am really stuck and struggling and I need to get this done very soon. Please help if you can! Thank you.