Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
3
Answers
If username stored in local storage open new web page
ahmed salah
8y
242
1
Reply
I have web page index have two input type text username and username2
and checkbox save and button save when client write username and username2 and checkbox save checked then click save button
it will store in local storage i dont have any problem in that
I need actually if username and username2 exist or stored in local storage go to web page index2
my code as bellow working but only i need to modify it if exist local storage go to web page index2
@{
Layout =
null
;
}
<!DOCTYPE html>
<html>
<head>
<meta name=
"viewport"
content=
"width=device-width"
/>
<title>Index</title>
<script src=
"~/Scripts/jquery-1.10.2.js"
></script>
<script>
$(
function
() {
if
(localStorage.chkbx && localStorage.chkbx !=
''
) {
$(
'#save'
).attr(
'checked'
,
'checked'
);
$(
'#username'
).val(localStorage.username);
$(
'#username2'
).val(localStorage.username2);
}
else
{
$(
'#remember_me'
).removeAttr(
'checked'
);
$(
'#username'
).val(
''
);
$(
'#username2'
).val(
''
);
}
$(
'#btn'
).click(
function
() {
if
($(
'#save'
).is(
':checked'
)) {
// save username and password
localStorage.username = $(
'#username'
).val();
localStorage.username2 = $(
'#username2'
).val();
localStorage.chkbx = $(
'#save'
).val();
}
else
{
localStorage.username =
''
;
localStorage.username2 =
''
;
localStorage.chkbx =
''
;
}
});
});
</script>
</head>
<body>
<div
class
=
"container"
>
<form
class
=
"form-signin"
>
<h2
class
=
"form-signin-heading"
>Please sign
in
</h2>
<input type=
"text"
class
=
"input-block-level"
placeholder=
"username"
id=
'username'
>
<input type=
"text"
class
=
"input-block-level"
placeholder=
"username2"
id=
"username2"
>
<label
class
=
"checkbox"
>
<input type=
"checkbox"
value=
"save"
id=
"save"
> save
</label>
<button
class
=
"btn btn-large btn-primary"
id=
"btn"
type=
"submit"
>save</button>
</form>
</div>
</body>
</html>
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
[Ask] Jquery auto complete more than one column
Could not position the SVG Element.