Sunday, 25 August 2013

Radiobutton validation using JQuery


This example for Radiobutton validation using JQuery

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Validate asp.net radiobuttonlist in JQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$('#btnSubmit').click(function() {
if ($('#rdbtnGender :radio:checked').length > 0) {
return true;
}
else {
alert('Please select Gender')
return false;
}
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td> <b>Select Gender:</b></td>
<td>
<asp:RadioButtonList ID="rdbtnGender" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="1" Text="Male" />
<asp:ListItem Value="2" Text="Female" />
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSubmit" Text="Submit" runat="server" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

No comments:

Post a Comment