Validate multiple ASP.Net TextBoxes using JavaScript and List the empty TextBoxes in alert box

Last Reply on Nov 12, 2012 10:15 AM By Mudassar

Posted on Nov 12, 2012 10:14 AM

Would like to know the concept behind the working of the URL below:
If any user clicks on the submit button without filling any information then a javascript pop up appears and all the important fields that has to displayed is shown one by one, I am aware about alert function of javascript but not aware to validate multiple textbox's using javascript.How to achieve this?

In the above mentioned URL directly click on the the submit button, you will understand what exactly I want.


Posted on Nov 12, 2012 10:15 AM

This way

    <script type="text/javascript">
        function Validate() {
            var message = "";
            if (document.getElementById("<%=txtFName.ClientID %>").value == "") {
                message += "First Name:\n";
            if (document.getElementById("<%=txtLName.ClientID %>").value == "") {
                message += "Last Name:\n";
            if (document.getElementById("<%=txtPhone.ClientID %>").value == "") {
                message += "Phone Number:\n";
            if (message != '') {
                message = "Please fill\n----------------------------\n" + message;
                return false;
            return true;

    First Name:
    <asp:TextBox ID="txtFName" runat="server"></asp:TextBox><br />
    Last Name:
    <asp:TextBox ID="txtLName" runat="server"></asp:TextBox><br />
    <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox><br />
    <asp:Button ID="Button1" runat="server" Text="Submit" OnClientClick="return Validate()" />