harshit verma

harshit verma

  • NA
  • 36
  • 2.5k

Javascript Issue

Aug 17 2018 1:12 AM
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.
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="KUD.aspx.cs" Inherits="Javascript_Testing.KUD" %>  
  2. <!DOCTYPE html>  
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head runat="server">  
  5. <title></title>  
  6. <script type="text/javascript" language="javascript">  
  7. function ValidateForm() {  
  8. debugger;  
  9. var result = true;  
  10. if (document.getElementById("<%=txtFName.ClientID%>").innerText == "") {  
  11. document.getElementById("<%=errFName.ClientID%>").innerHTML = "First Name is required!";  
  12. }  
  13. }  
  14. </script>  
  15. </head>  
  16. <body>  
  17. <form id="form1" runat="server">  
  18. <div>  
  19. <table border="1" style="border-style: solid">  
  20. <tr>  
  21. <td>  
  22. <asp:Label ID="lblFName" runat="server">First Name</asp:Label></td>  
  23. <td>  
  24. <asp:TextBox ID="txtFName" runat="server"></asp:TextBox></td>  
  25. <td>  
  26. <asp:Label ID="errFName" runat="server"></asp:Label></td>  
  27. </tr>  
  28. <tr>  
  29. <td>  
  30. <asp:Label ID="lblLName" runat="server">Last Name</asp:Label></td>  
  31. <td>  
  32. <asp:TextBox ID="txtLName" runat="server"></asp:TextBox></td>  
  33. <td>  
  34. <asp:Label ID="errLName" runat="server"></asp:Label></td>  
  35. </tr>  
  36. <tr>  
  37. <td>  
  38. <asp:Label ID="lblEmail" runat="server">E-Mail</asp:Label></td>  
  39. <td>  
  40. <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></td>  
  41. <td>  
  42. <asp:Label ID="errEmail" runat="server"></asp:Label></td>  
  43. </tr>  
  44. <tr>  
  45. <td>  
  46. <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" OnClientClick="ValidateForm()" />  
  47. </td>  
  48. </tr>  
  49. </table>  
  50. </div>  
  51. </form>  
  52. </body>  
  53. </html>  
Thanks

Answers (9)