Hi
I have a javascript in which I am trying to validate data and display error message in a label but the label is not displaying the error message. Below is my code.
Kindly help me with this issue.
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="KUD.aspx.cs" Inherits="Javascript_Testing.KUD" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <script type="text/javascript" language="javascript">
- function ValidateForm() {
- debugger;
- var result = true;
- if (document.getElementById("<%=txtFName.ClientID%>").innerText == "") {
- document.getElementById("<%=errFName.ClientID%>").innerHTML = "First Name is required!";
- }
- }
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <table border="1" style="border-style: solid">
- <tr>
- <td>
- <asp:Label ID="lblFName" runat="server">First Name</asp:Label></td>
- <td>
- <asp:TextBox ID="txtFName" runat="server"></asp:TextBox></td>
- <td>
- <asp:Label ID="errFName" runat="server"></asp:Label></td>
- </tr>
- <tr>
- <td>
- <asp:Label ID="lblLName" runat="server">Last Name</asp:Label></td>
- <td>
- <asp:TextBox ID="txtLName" runat="server"></asp:TextBox></td>
- <td>
- <asp:Label ID="errLName" runat="server"></asp:Label></td>
- </tr>
- <tr>
- <td>
- <asp:Label ID="lblEmail" runat="server">E-Mail</asp:Label></td>
- <td>
- <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></td>
- <td>
- <asp:Label ID="errEmail" runat="server"></asp:Label></td>
- </tr>
- <tr>
- <td>
- <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" OnClientClick="ValidateForm()" />
- </td>
- </tr>
- </table>
- </div>
- </form>
- </body>
- </html>
Thanks