TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abdul Amin Khan
1.1k
605
21.5k
Why i am getting error Cannot set property 'value' of null
Jun 30 2020 2:17 PM
<!DOCTYPE html>
<html>
<head>
<meta charset=
"UTF-8"
>
<meta name=
"viewport"
content=
"width=device-width"
/>
<title>Welcome to Apna Padosi - Admin</title>
<link rel=
'stylesheet prefetch'
href=
'https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css'
>
<link rel=
"stylesheet"
href=
"/css/style.css"
>
</head>
<body>
<div>
<div
class
=
"login-form"
>
<h1>ApnaPadosi Login</h1>
<div
class
=
"form-group"
>
<input
class
=
"form-control"
id=
"txtUserName"
name=
"txtUserName"
onkeyup=
"removeBlankValidation(this)"
placeholder=
"User Name"
type=
"text"
value=
""
/>
<i
class
=
"fa fa-user"
></i>
</div>
<div
class
=
"form-group log-status"
>
<input
class
=
"form-control"
id=
"txtPassword"
name=
"txtPassword"
onkeyup=
"removeBlankValidation(this)"
placeholder=
"Password"
type=
"password"
value=
""
/>
<i
class
=
"fa fa-lock"
></i>
</div>
<span
class
=
"alert"
id=
"errormsg"
>Invalid Credentials</span>
<a
class
=
"link"
href=
"#"
>Lost your password?</a>
<button id=
"btnLogin"
type=
"button"
class
=
"log-btn"
onclick=
"login_click()"
>Log
in
</button>
</div>
</div>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"
></script>
<script type=
"text/javascript"
src=
"/Scripts/CustomScript.js"
></script>
</body>
</html>
custom script
function
login_click() {
//if (document.getElementById("#txtUserName") == null) {
// alert('ss');
//}
//document.getElementById("#txtUserName").removeAttribute('style');
//document.getElementById("#txtPassword").removeAttribute('style');
if
($(
'#txtUserName'
).val() ==
""
) {
document.getElementById(
"txtUserName"
).style.borderColor =
"red"
;
return
;
}
if
($(
'#txtPassword'
).val() ==
""
) {
document.getElementById(
"txtPassword"
).style.borderColor =
"red"
;
return
;
}
var
UserName = $(
'#txtUserName'
).val();
var
Password = $(
'#txtPassword'
).val();
$.ajax({
url:
"/Login/AuthenticateLogin"
,
type:
"POST"
,
data: {
encuname: UserName,
encpwd: Password
},
cache:
false
,
async:
true
,
dataType:
"json"
,
success:
function
(data) {
if
(data.Success) {
window.location.href =
"/Home/Index"
;
}
else
{
document.getElementById(
"#txtPassword"
).value =
""
;
$(
'.alert'
).fadeIn(500);
setTimeout(
"$('.alert').fadeOut(1500);"
, 3000);
}
},
error:
function
() {
document.getElementById(
"#txtPassword"
).value =
""
;
$(
'.alert'
).fadeIn(500);
setTimeout(
"$('.alert').fadeOut(1500);"
, 3000);
}
});
}
function
removeBlankValidation(txtBox) {
if
(txtBox.value !=
""
) {
txtBox.removeAttribute(
'style'
);
}
}
Reply
Answers (
1
)
CustomValidation not working on asp.net mvc form?
how to zip a folder in asp.net?