Validate ASP.Net RadioButtonList using JavaScript Example
Validate ASP.Net RadioButtonList using JavaScript in Asp.Net using C#:
In this post we consider an Example JavaScript for Radiobuttonlist and validate the Radiobuttonlist
using JavaScript. As we know that javascript is a scripting language. In this
asp.net tutorial Example blog we give many post related to the Radiobuttonlist
control these are:
Other Radiobuttonlist related post or example:
- How To bind RadioButtonList Control From data base
- Access RadioButtonList Item Using VBScript
- Use radiobuttonlist with VB
- Example of jQuery Validate on Radiobuttonlist in Asp.Net using C#
- Example of RadioButtonList control.
- Html Radio Button
- ASP.NET RadioButton Control
- Hide radio buttons in JavaScript on button click
Using JavaScript with ASP.Net RadioButtonList Control:
function ValidateRadioButtonList() {
var isChecked = false;
var rbl= document.getElementById("<%=rbl.ClientID%>");
var radioButtons = rbl.getElementsByTagName("input");
for (var i = 0; i
< radioButtons.length; i++) {
if (radioButtons[i].checked) {
isChecked = true;
break;
}
}
if (!isChecked) {
alert("Please select one from the
list.");
}
else
{
return isChecked;
alert("selected...");
}
return isChecked;
}
Use javascript function on button onclient click event:
<asp:Button ID="btnSave" OnClientClick="return ValidateRadioButtonList();"
runat="server" Text="ok" Width="92px" />
RadioButtonList validate using jQuery in Asp.net:
Here we take give jquery function of performing the
validation on Radiobuttonlist in asp.net page.
$(document).ready(function
() {
$('#btnSubmit').click(function () {
if ($('#rdbtn
:radio:checked').length > 0) {
return true;
}
else {
alert('Please chooes one ')
return false;
}
})
})
For full code and get example of validation of radiobutton click here……..
Checkboxlist jQuery Validate Example :
$(document).ready(function
() {
$('#btnSubmit').click(function () {
if ($('#chktech
input:checked').length > 0) {
return true;
}
else {
alert('Please select atleast one')
return false;
}
})
});
For full code and get example checkboxlist validation click here……..
Validate radio button list in javascript in asp.net:
JavaScript Validate Example in asp.net
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="Radiobuttonlist_validation.aspx.cs"
Inherits="Radiobuttonlist_validation"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net tutorial by parijat mishra |
RadioButtonList Validation using JavaScript</title>
<script type="text/javascript">
function ValidateRadioButtonList() {
var isChecked = false;
var rbl= document.getElementById("<%=rbl.ClientID%>");
var radioButtons = rbl.getElementsByTagName("input");
for (var i = 0; i
< radioButtons.length; i++) {
if (radioButtons[i].checked) {
isChecked = true;
break;
}
}
if (!isChecked) {
alert("Please select one from the
list.");
}
else
{
return isChecked;
alert("selected...");
}
return isChecked;
}
</script>
<style type="text/css">
.style1
{
width: 269px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
select minmum one
</td>
<td>
:
</td>
<td
class="style1">
<asp:RadioButtonList ID="rbl" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="1" Text="option1" />
<asp:ListItem Value="2" Text="option2" />
<asp:ListItem Value="3" Text="option3" />
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td
colspan="3">
</td>
</tr>
<tr>
<td
colspan="2">
</td>
<td
class="style1">
<asp:Button ID="btnSave"
OnClientClick="return
ValidateRadioButtonList();" runat="server"
Text="Save" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Other asp.net related Examples:
- On mouse over event show tooltip dropdownlist items by using C# example
- Example of Adding ToolTip for each Dropdown List Item in C#
- DropDownList Programmatically add items on Button Click in ASP.Net using C# Example
- Containing sub string in string Using JavaScript
- Display tooltip from database for dropdownlist items in asp.net c# example
- How to Add Reference of .dll file in Asp.net web site/Application
- Hide radio buttons in JavaScript on button click
- Add or bind tooltip for dropdownlist items in asp.net by C#
- How to use asp ListView control in asp.net:
- how to use Captcha in asp.net Second post
- Sending mail from web application using google Mail ID
- How to Make Data Table By C# code in Asp.net Programming:
- how to add capcha in Asp.net programming
- how to use CAPTCHA in asp.net
- Example of Crystal report(Crystal_report_in asp.net programming )
- How to Make a HTML Table by C# code in asp.net programming
- Example jQuery Validate on CheckBoxList using C#
Comments
Post a Comment