Welcome to my Default.aspx page
<td>Radio Control</td>
<td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" >
<asp:ListItem Text = "One" Value = "1"></asp:ListItem>
<asp:ListItem Text = "Two" Value = "2"></asp:ListItem>
<asp:ListItem Text = "Three" Value = "3"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td><div id="Div1" style="color:Red;display:none"></div></td>
</tr>
<tr>
<td>Dropdown Menu </td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" >
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<br />
<center>
<asp:Button ID="Button1" runat="server" Text="Edit"/>
<asp:Button ID="Button2" runat="server" Text="Choose from Dropdown" OnClientClick="return ValidateDropDown('DropDownList1');" />
<asp:Button ID="Button3" runat="server" Text="Validate Radio" OnClientClick = "return ValRad(document.getElementById('RadioButtonList1'));" />
</center>
This is a script from my separate JavaScript file:
function ValRad(CntrlID) {
alert("Checking Radio Buttons");
var RB1 = CntrlID;
alert("Processing..");
var radio = RB1.getElementsByTagName("input");
alert("Verifying..");
var isChecked = false;
alert("Proceeding..");
for (var i = 0; i < radio.length; i++) {
if (radio[i].checked) {
isChecked = true;
break;
}
}
if (!isChecked) {
alert("Please select an item");
}
return isChecked;
}
I am facing issues validating both the radiobuttonlist and dropdownlist, any help would be greatly appreciated. Apologies for any formatting errors as I am new here.