This time i want to explain, How to validate RadioButtonList using javascript in asp.net.
In this below example i am going to explain to validate radiobuttonlist, to select at least one radio button.
Technology : asp.net ,HTML ,JAVASCRIPT
Please follow the below example :
Write the below javascript in asp.net page (.aspx) page header section.
<script type ="text/javascript" language="javascript">
function Validate() {
var RB1 = document.getElementById("<%=RadioButtonList1.ClientID%>");
var radio = RB1.getElementsByTagName("input");
var isChecked = false;
for (var i = 0; i < radio.length; i++) {
if (radio[i].checked) {
isChecked = true;
break;
}
}
if (!isChecked) {
alert("Please select an item");
}
return isChecked;
}
</script>
call the above javascript function on button click event as follows:
<asp:Button ID="btnValidateRadioList" runat="server" Text="Validate"
OnClientClick = "return Validate();"/>
Hope this is Help full
No comments:
Post a Comment