javascript validations radiobutton list etc…..(full page)
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Untitled Page</title>
<script type=”text/javascript”>
function ValidateNumbers()
{
if(document.getElementById(‘txtNumber’).value!=”)
{
var input= document.getElementById(‘txtNumber’).value;
// var testName =/^([0-9])*$/;
// if(!testName.test(input))
// {
// alert(”Enter only numeric values”);
// return false;
// }
if (input == null || !input.toString().match(/^[-]?\d*\.?\d*$/))
{
alert(“Enter only numeric values”);
return false;
}
}
if(document.getElementById(‘ddlInput’).selectedIndex == 0)
{
alert(“Select Numbers”);
return false;
}
//validate radio list
var listItemArray = document.getElementsByName(‘ddlColors’);
var isItemChecked = false;
for (var i=0; i<listItemArray.length; i++)
{
var listItem = listItemArray[i];
if ( listItem.checked )
{
//alert(listItem.value);
isItemChecked = true;
}
}
if ( isItemChecked == false )
{
alert(‘Nothing is checked!’);
return false;
}
}
</script>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:TextBox ID=”txtNumber” runat=”server”></asp:TextBox>
<asp:DropDownList ID=”ddlInput” runat=”server”>
<asp:ListItem Text=”Select”></asp:ListItem>
<asp:ListItem Text=”One”></asp:ListItem>
<asp:ListItem Text=”Two”></asp:ListItem>
<asp:ListItem Text=”Three”></asp:ListItem>
</asp:DropDownList>
<asp:RadioButtonList ID=”ddlColors” runat=”server”>
<asp:ListItem Text=”Red”></asp:ListItem>
<asp:ListItem Text=”Blue”></asp:ListItem>
<asp:ListItem Text=”White”></asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID=”btnSubmit” runat=”server” OnClientClick=”return ValidateNumbers()” Text=”Submit” />
</div>
</form>
</body>
</html>
No comments yet.
Leave a comment
-
Archives
- June 2009 (2)
- April 2009 (2)
- August 2008 (2)
- July 2008 (9)
- June 2008 (10)
- May 2008 (1)
- March 2008 (1)
- December 2007 (2)
-
Categories
-
RSS
Entries RSS
Comments RSS