Abdul Amin Khan

Abdul Amin Khan

  • 1.4k
  • 463
  • 9.9k

Why i am getting error Cannot set property 'value' of null

Jun 30 2020 2:17 PM
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <meta charset="UTF-8">  
  5. <meta name="viewport" content="width=device-width" />  
  6. <title>Welcome to Apna Padosi - Admin</title>  
  7. <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css'>  
  8. <link rel="stylesheet" href="/css/style.css">  
  9. </head>  
  10. <body>  
  11. <div>  
  12. <div class="login-form">  
  13. <h1>ApnaPadosi Login</h1>  
  14. <div class="form-group">  
  15. <input class="form-control" id="txtUserName" name="txtUserName" onkeyup="removeBlankValidation(this)" placeholder="User Name" type="text" value="" />  
  16. <i class="fa fa-user"></i>  
  17. </div>  
  18. <div class="form-group log-status">  
  19. <input class="form-control" id="txtPassword" name="txtPassword" onkeyup="removeBlankValidation(this)" placeholder="Password" type="password" value="" />  
  20. <i class="fa fa-lock"></i>  
  21. </div>  
  22. <span class="alert" id="errormsg">Invalid Credentials</span>  
  23. <a class="link" href="#">Lost your password?</a>  
  24. <button id="btnLogin" type="button" class="log-btn" onclick="login_click()">Log in</button>  
  25. </div>  
  26. </div>  
  27. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>  
  28. <script type="text/javascript" src="/Scripts/CustomScript.js"></script>  
  29. </body>  
  30. </html>  
  31. custom script  
  32. function login_click() {  
  33. //if (document.getElementById("#txtUserName") == null) {  
  34. // alert('ss');  
  35. //}  
  36. //document.getElementById("#txtUserName").removeAttribute('style');  
  37. //document.getElementById("#txtPassword").removeAttribute('style');  
  38. if ($('#txtUserName').val() == "") {  
  39. document.getElementById("txtUserName").style.borderColor = "red";  
  40. return;  
  41. }  
  42. if ($('#txtPassword').val() == "") {  
  43. document.getElementById("txtPassword").style.borderColor = "red";  
  44. return;  
  45. }  
  46. var UserName = $('#txtUserName').val();  
  47. var Password = $('#txtPassword').val();  
  48. $.ajax({  
  49. url: "/Login/AuthenticateLogin",  
  50. type: "POST",  
  51. data: {  
  52. encuname: UserName,  
  53. encpwd: Password  
  54. },  
  55. cache: false,  
  56. async: true,  
  57. dataType: "json",  
  58. success: function (data) {  
  59. if (data.Success) {  
  60. window.location.href = "/Home/Index";  
  61. }  
  62. else {  
  63. document.getElementById("#txtPassword").value = "";  
  64. $('.alert').fadeIn(500);  
  65. setTimeout("$('.alert').fadeOut(1500);", 3000);  
  66. }  
  67. },  
  68. error: function () {  
  69. document.getElementById("#txtPassword").value = "";  
  70. $('.alert').fadeIn(500);  
  71. setTimeout("$('.alert').fadeOut(1500);", 3000);  
  72. }  
  73. });  
  74. }  
  75. function removeBlankValidation(txtBox) {  
  76. if (txtBox.value != "") {  
  77. txtBox.removeAttribute('style');  
  78. }  
  79. }  

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (1)