Kuzhikkattil

Just another WordPress.com weblog

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>

 

July 14, 2008 - Posted by kuzhikkattil | Uncategorized | | No Comments Yet

No comments yet.

Leave a comment